diff --git a/Source/Glide64/3dmath.cpp b/Source/Glide64/3dmath.cpp index b8b9ac206..0d51f199c 100644 --- a/Source/Glide64/3dmath.cpp +++ b/Source/Glide64/3dmath.cpp @@ -125,8 +125,8 @@ void calc_sphere (VERTEX *v) int s_scale, t_scale; if (settings.hacks&hack_Chopper) { - s_scale = min(rdp.tiles[rdp.cur_tile].org_s_scale >> 6, rdp.tiles[rdp.cur_tile].lr_s); - t_scale = min(rdp.tiles[rdp.cur_tile].org_t_scale >> 6, rdp.tiles[rdp.cur_tile].lr_t); + s_scale = minval(rdp.tiles[rdp.cur_tile].org_s_scale >> 6, rdp.tiles[rdp.cur_tile].lr_s); + t_scale = minval(rdp.tiles[rdp.cur_tile].org_t_scale >> 6, rdp.tiles[rdp.cur_tile].lr_t); } else { diff --git a/Source/Glide64/Combine.cpp b/Source/Glide64/Combine.cpp index a77d5ff6a..589fc6dc7 100644 --- a/Source/Glide64/Combine.cpp +++ b/Source/Glide64/Combine.cpp @@ -669,9 +669,9 @@ COMBINE cmb; (uint8_t)( ((color1 & 0x0000FF00) >> 8) * (((color2 & 0x0000FF00) >> 8) /255.0f) ) << 8 ; \ } #define CC_C1SUBC2(color1, color2) { \ - cmb.ccolor=(uint8_t)( max(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) ) << 24 | \ - (uint8_t)( max(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) ) << 16 | \ - (uint8_t)( max(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) ) << 8 ; \ + cmb.ccolor=(uint8_t)( maxval(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) ) << 24 | \ + (uint8_t)( maxval(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) ) << 16 | \ + (uint8_t)( maxval(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) ) << 8 ; \ } #define CC_COLMULBYTE(color, byte) { \ float factor = byte/255.0f; \ @@ -705,9 +705,9 @@ COMBINE cmb; rdp.cmb_flags |= flag; \ } #define XSHADEC1MC2(color1, color2, flag) { \ - rdp.col[0] *= (float)( max(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) )/255.0f; \ - rdp.col[1] *= (float)( max(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) )/255.0f; \ - rdp.col[2] *= (float)( max(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) )/255.0f; \ + rdp.col[0] *= (float)( maxval(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) )/255.0f; \ + rdp.col[1] *= (float)( maxval(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) )/255.0f; \ + rdp.col[2] *= (float)( maxval(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) )/255.0f; \ rdp.cmb_flags |= flag; \ } #define XSHADE_BYTE(byte, flag) { \ @@ -756,9 +756,9 @@ COMBINE cmb; rdp.cmb_flags |= flag; \ } #define XSHADEC1MC2ADD(color1, color2, flag) { \ - rdp.coladd[0] *= (float)( max(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) )/255.0f; \ - rdp.coladd[1] *= (float)( max(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) )/255.0f; \ - rdp.coladd[2] *= (float)( max(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) )/255.0f; \ + rdp.coladd[0] *= (float)( maxval(0, (int)((color1 & 0xFF000000) >> 24) - (int)((color2 & 0xFF000000) >> 24)) )/255.0f; \ + rdp.coladd[1] *= (float)( maxval(0, (int)((color1 & 0x00FF0000) >> 16) - (int)((color2 & 0x00FF0000) >> 16)) )/255.0f; \ + rdp.coladd[2] *= (float)( maxval(0, (int)((color1 & 0x0000FF00) >> 8) - (int)((color2 & 0x0000FF00) >> 8)) )/255.0f; \ rdp.cmb_flags |= flag; \ } #define SUBSHADE_PRIM() XSHADEADD(rdp.prim_color, CMB_SUB) @@ -811,7 +811,7 @@ COMBINE cmb; rdp.cmb_flags |= flag; \ } #define XSHADEC1MC2_A(color1, color2, flag) { \ - rdp.col[3] *= (float)( max(0, (int)(color1 & 0xFF) - (int)(color2 & 0xFF)) ) / 255.0f; \ + rdp.col[3] *= (float)( maxval(0, (int)(color1 & 0xFF) - (int)(color2 & 0xFF)) ) / 255.0f; \ rdp.cmb_flags |= flag; \ } #define MULSHADE_A_PRIM() XSHADE_A(rdp.prim_color, CMB_A_MULT) @@ -1931,9 +1931,9 @@ static void cc__prim_inter_env_using_enva__mul_shade() uint32_t er = (rdp.env_color >> 24) & 0xFF; uint32_t eg = (rdp.env_color >> 16) & 0xFF; uint32_t eb = (rdp.env_color >> 8) & 0xFF; - uint32_t r = min(255, (uint32_t)(er*ea + pr*ea_i)); - uint32_t g = min(255, (uint32_t)(eg*ea + pg*ea_i)); - uint32_t b = min(255, (uint32_t)(eb*ea + pb*ea_i)); + uint32_t r = minval(255, (uint32_t)(er*ea + pr*ea_i)); + uint32_t g = minval(255, (uint32_t)(eg*ea + pg*ea_i)); + uint32_t b = minval(255, (uint32_t)(eb*ea + pb*ea_i)); uint32_t col = (r << 24) | (g << 16) | (b << 8) | 0xFF; CCMB(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, @@ -8557,9 +8557,9 @@ static void cc__prim_inter_one_using_env__mul_shade() GR_COMBINE_OTHER_CONSTANT); CC_1SUBPRIM(); CC_C1MULC2(cmb.ccolor, rdp.env_color); - cmb.ccolor = (uint8_t)(min(255, (int)((cmb.ccolor & 0xFF000000) >> 24) + (int)((rdp.prim_color & 0xFF000000) >> 24))) << 24 | - (uint8_t)(min(255, (int)((cmb.ccolor & 0x00FF0000) >> 16) + (int)((rdp.prim_color & 0x00FF0000) >> 16))) << 16 | - (uint8_t)(min(255, (int)((cmb.ccolor & 0x0000FF00) >> 8) + (int)((rdp.prim_color & 0x0000FF00) >> 8))) << 8; + cmb.ccolor = (uint8_t)(minval(255, (int)((cmb.ccolor & 0xFF000000) >> 24) + (int)((rdp.prim_color & 0xFF000000) >> 24))) << 24 | + (uint8_t)(minval(255, (int)((cmb.ccolor & 0x00FF0000) >> 16) + (int)((rdp.prim_color & 0x00FF0000) >> 16))) << 16 | + (uint8_t)(minval(255, (int)((cmb.ccolor & 0x0000FF00) >> 8) + (int)((rdp.prim_color & 0x0000FF00) >> 8))) << 8; } static void cc__env_inter_prim_using_t0a__mul_t0() diff --git a/Source/Glide64/FBtoScreen.cpp b/Source/Glide64/FBtoScreen.cpp index 2ec593cf0..78117c85b 100644 --- a/Source/Glide64/FBtoScreen.cpp +++ b/Source/Glide64/FBtoScreen.cpp @@ -159,7 +159,7 @@ static void DrawRE2Video256(FB_TO_SCREEN_INFO & fb_info) uint16_t * dst = tex; uint32_t col; uint8_t r, g, b; - fb_info.height = min(256, fb_info.height); + fb_info.height = minval(256, fb_info.height); for (uint32_t h = 0; h < fb_info.height; h++) { for (uint32_t w = 0; w < 256; w++) @@ -308,7 +308,7 @@ bool DrawFrameBufferToScreen(FB_TO_SCREEN_INFO & fb_info) return false; uint32_t width = fb_info.lr_x - fb_info.ul_x + 1; uint32_t height = fb_info.lr_y - fb_info.ul_y + 1; - uint32_t max_size = min(voodoo.max_tex_size, 512); + uint32_t max_size = minval(voodoo.max_tex_size, 512); if (width > (uint32_t)max_size || height > (uint32_t)max_size) { DrawFrameBufferToScreen256(fb_info); diff --git a/Source/Glide64/Main.cpp b/Source/Glide64/Main.cpp index 96384995c..832afe2b4 100644 --- a/Source/Glide64/Main.cpp +++ b/Source/Glide64/Main.cpp @@ -802,7 +802,7 @@ void DisplayLoadProgress(const wchar_t *format, ...) float x; set_message_combiner(); output(382, 380, 1, "LOADING TEXTURES. PLEASE WAIT..."); - int len = min((int)strlen(buf) * 8, 1024); + int len = minval((int)strlen(buf) * 8, 1024); x = (1024 - len) / 2.0f; output(x, 360, 1, buf); grBufferSwap(0); diff --git a/Source/Glide64/TexBuffer.cpp b/Source/Glide64/TexBuffer.cpp index e11411ea6..e47aa1db2 100644 --- a/Source/Glide64/TexBuffer.cpp +++ b/Source/Glide64/TexBuffer.cpp @@ -55,14 +55,14 @@ static TBUFF_COLOR_IMAGE * AllocateTextureBuffer(COLOR_IMAGE & cimage) texbuf.height = cimage.height; texbuf.format = cimage.format; texbuf.size = cimage.size; - texbuf.scr_width = min(cimage.width * rdp.scale_x, settings.scr_res_x); - float height = min(rdp.vi_height, cimage.height); + texbuf.scr_width = minval(cimage.width * rdp.scale_x, settings.scr_res_x); + float height = minval(rdp.vi_height, cimage.height); if (cimage.status == ci_copy_self || (cimage.status == ci_copy && cimage.width == rdp.frame_buffers[rdp.main_ci_index].width)) height = rdp.vi_height; texbuf.scr_height = height * rdp.scale_y; // texbuf.scr_height = texbuf.height * rdp.scale_y; - uint16_t max_size = max((uint16_t)texbuf.scr_width, (uint16_t)texbuf.scr_height); + uint16_t max_size = maxval((uint16_t)texbuf.scr_width, (uint16_t)texbuf.scr_height); if (max_size > voodoo.max_tex_size) //texture size is too large return 0; uint32_t tex_size; diff --git a/Source/Glide64/TexCache.cpp b/Source/Glide64/TexCache.cpp index 8d6fc70af..8594760af 100644 --- a/Source/Glide64/TexCache.cpp +++ b/Source/Glide64/TexCache.cpp @@ -215,28 +215,28 @@ void GetTexInfo(int id, int tile) if ((rdp.tiles[tile].clamp_s && tile_width <= 256) || (mask_width > 256)) { // loading width - width = min(mask_width, tile_width); + width = minval(mask_width, tile_width); // actual width rdp.tiles[tile].width = tile_width; } else { // wrap all the way - width = min(mask_width, tile_width); // changed from mask_width only + width = minval(mask_width, tile_width); // changed from mask_width only rdp.tiles[tile].width = width; } if ((rdp.tiles[tile].clamp_t && tile_height <= 256) || (mask_height > 256)) { // loading height - height = min(mask_height, tile_height); + height = minval(mask_height, tile_height); // actual height rdp.tiles[tile].height = tile_height; } else { // wrap all the way - height = min(mask_height, tile_height); + height = minval(mask_height, tile_height); rdp.tiles[tile].height = height; } } @@ -256,7 +256,7 @@ void GetTexInfo(int id, int tile) if ((rdp.tiles[tile].clamp_s && tile_width <= 256))//|| (mask_width > 256)) { // loading width - width = min(mask_width, tile_width); + width = minval(mask_width, tile_width); // actual width rdp.tiles[tile].width = tile_width; } @@ -270,7 +270,7 @@ void GetTexInfo(int id, int tile) if ((rdp.tiles[tile].clamp_t && tile_height <= 256) || (mask_height > 256)) { // loading height - height = min(mask_height, tile_height); + height = minval(mask_height, tile_height); // actual height rdp.tiles[tile].height = tile_height; } @@ -333,7 +333,7 @@ void GetTexInfo(int id, int tile) wid_64 = wid_64 >> 3; // Texture too big for tmem & needs to wrap? (trees in mm) - if (rdp.tiles[tile].t_mem + min(height, tile_height) * (rdp.tiles[tile].line << 3) > 4096) + if (rdp.tiles[tile].t_mem + minval(height, tile_height) * (rdp.tiles[tile].line << 3) > 4096) { LRDP("TEXTURE WRAPS TMEM!!! "); @@ -370,7 +370,7 @@ void GetTexInfo(int id, int tile) else //32b texture { int line_2 = line >> 1; - int wid_64_2 = max(1, wid_64 >> 1); + int wid_64_2 = maxval(1, wid_64 >> 1); crc = textureCRC(addr, wid_64_2, crc_height, line_2); crc += textureCRC(addr + 0x800, wid_64_2, crc_height, line_2); } @@ -380,7 +380,7 @@ void GetTexInfo(int id, int tile) { crc = 0xFFFFFFFF; wxUIntPtr addr = wxPtrToUInt(rdp.tmem) + (rdp.tiles[tile].t_mem << 3); - uint32_t line2 = max(line, 1); + uint32_t line2 = maxval(line, 1); if (rdp.tiles[tile].size < 3) { line2 <<= 3; @@ -395,7 +395,7 @@ void GetTexInfo(int id, int tile) line2 <<= 2; //32b texel is split in two 16b parts, so bpl/2 and line/2. //Min value for bpl is 4, because when width==1 first 2 bytes of tmem will not be used. - bpl = max(bpl >> 1, 4); + bpl = maxval(bpl >> 1, 4); for (int y = 0; y < crc_height; y++) { crc = CRC32(crc, reinterpret_cast(addr), bpl); @@ -981,9 +981,9 @@ uint32_t sizeBytes[4] = { 0, 1, 2, 4 }; inline uint32_t Txl2Words(uint32_t width, uint32_t size) { if (size == 0) - return max(1, width / 16); + return maxval(1, width / 16); else - return max(1, width*sizeBytes[size] / 8); + return maxval(1, width*sizeBytes[size] / 8); } inline uint32_t ReverseDXT(uint32_t val, uint32_t /*lrs*/, uint32_t width, uint32_t size) @@ -1101,7 +1101,7 @@ void LoadTex(int id, int tmu) } // Calculate the maximum size - int size_max = max(size_x, size_y); + int size_max = maxval(size_x, size_y); uint32_t real_x = size_max, real_y = size_max; switch (size_max) { @@ -1308,7 +1308,7 @@ void LoadTex(int id, int tmu) bpl = info.tex_width << info.tex_size >> 1; addr += (info.tile_ul_t * bpl) + (((info.tile_ul_s << info.tex_size) + 1) >> 1); - tile_width = min(info.tile_width, info.tex_width); + tile_width = minval(info.tile_width, info.tex_width); if (info.tex_size > rdp.tiles[td].size) tile_width <<= info.tex_size - rdp.tiles[td].size; @@ -1409,11 +1409,11 @@ void LoadTex(int id, int tmu) int min_x, min_y; if (rdp.tiles[td].mask_s != 0) - min_x = min((int)real_x, 1 << rdp.tiles[td].mask_s); + min_x = minval((int)real_x, 1 << rdp.tiles[td].mask_s); else min_x = real_x; if (rdp.tiles[td].mask_t != 0) - min_y = min((int)real_y, 1 << rdp.tiles[td].mask_t); + min_y = minval((int)real_y, 1 << rdp.tiles[td].mask_t); else min_y = real_y; diff --git a/Source/Glide64/TexLoad32b.h b/Source/Glide64/TexLoad32b.h index 09f2c8b76..bd346a132 100644 --- a/Source/Glide64/TexLoad32b.h +++ b/Source/Glide64/TexLoad32b.h @@ -48,7 +48,7 @@ uint32_t Load32bRGBA (wxUIntPtr dst, wxUIntPtr src, int wid_64, int height, int if (height < 1) height = 1; const uint16_t *tmem16 = (uint16_t*)rdp.tmem; const uint32_t tbase = (src - (wxUIntPtr)rdp.tmem) >> 1; - const uint32_t width = max(1, wid_64 << 1); + const uint32_t width = maxval(1, wid_64 << 1); const int ext = real_width - width; line = width + (line>>2); uint32_t s, t, c; diff --git a/Source/Glide64/TexMod.h b/Source/Glide64/TexMod.h index fb5955dad..5907384a8 100644 --- a/Source/Glide64/TexMod.h +++ b/Source/Glide64/TexMod.h @@ -132,9 +132,9 @@ static void mod_col_inter_col1_using_tex (uint16_t *dst, int size, uint32_t colo percent_r = ((col >> 8) & 0xF) / 15.0f; percent_g = ((col >> 4) & 0xF) / 15.0f; percent_b = (col & 0xF) / 15.0f; - r = min(15, (uint8_t)((1.0f-percent_r) * cr0 + percent_r * cr1 + 0.0001f)); - g = min(15, (uint8_t)((1.0f-percent_g) * cg0 + percent_g * cg1 + 0.0001f)); - b = min(15, (uint8_t)((1.0f-percent_b) * cb0 + percent_b * cb1 + 0.0001f)); + r = minval(15, (uint8_t)((1.0f-percent_r) * cr0 + percent_r * cr1 + 0.0001f)); + g = minval(15, (uint8_t)((1.0f-percent_g) * cg0 + percent_g * cg1 + 0.0001f)); + b = minval(15, (uint8_t)((1.0f-percent_b) * cb0 + percent_b * cb1 + 0.0001f)); *(dst++) = a | (r << 8) | (g << 4) | b; } } @@ -312,15 +312,15 @@ static void mod_tex_sub_col_mul_fac_add_tex (uint16_t *dst, int size, uint32_t c col = *dst; a = col & 0xF000; r = (float)((col >> 8) & 0xF); - r = /*max(*/(r - cr) * percent/*, 0.0f)*/ + r; + r = /*maxval(*/(r - cr) * percent/*, 0.0f)*/ + r; if (r > 15.0f) r = 15.0f; if (r < 0.0f) r = 0.0f; g = (float)((col >> 4) & 0xF); - g = /*max(*/(g - cg) * percent/*, 0.0f)*/ + g; + g = /*maxval(*/(g - cg) * percent/*, 0.0f)*/ + g; if (g > 15.0f) g = 15.0f; if (g < 0.0f) g = 0.0f; b = (float)(col & 0xF); - b = /*max(*/(b - cb) * percent/*, 0.0f)*/ + b; + b = /*maxval(*/(b - cb) * percent/*, 0.0f)*/ + b; if (b > 15.0f) b = 15.0f; if (b < 0.0f) b = 0.0f; @@ -350,9 +350,9 @@ static void mod_tex_scale_col_add_col (uint16_t *dst, int size, uint32_t color0, percent_r = ((col >> 8) & 0xF) / 15.0f; percent_g = ((col >> 4) & 0xF) / 15.0f; percent_b = (col & 0xF) / 15.0f; - r = min(15, (uint8_t)(percent_r * cr0 + cr1 + 0.0001f)); - g = min(15, (uint8_t)(percent_g * cg0 + cg1 + 0.0001f)); - b = min(15, (uint8_t)(percent_b * cb0 + cb1 + 0.0001f)); + r = minval(15, (uint8_t)(percent_r * cr0 + cr1 + 0.0001f)); + g = minval(15, (uint8_t)(percent_g * cg0 + cg1 + 0.0001f)); + b = minval(15, (uint8_t)(percent_b * cb0 + cb1 + 0.0001f)); *(dst++) = a | (r << 8) | (g << 4) | b; } } @@ -417,9 +417,9 @@ static void mod_tex_sub_col (uint16_t *dst, int size, uint32_t color) { col = *dst; a = (uint8_t)(col & 0xF000); - r = (uint8_t)max((((col >> 8) & 0xF) - cr), 0); - g = (uint8_t)max((((col >> 4) & 0xF) - cg), 0); - b = (uint8_t)max(((col & 0xF) - cb), 0); + r = (uint8_t)maxval((((col >> 8) & 0xF) - cr), 0); + g = (uint8_t)maxval((((col >> 4) & 0xF) - cg), 0); + b = (uint8_t)maxval(((col & 0xF) - cb), 0); *(dst++) = (a << 12) | (r << 8) | (g << 4) | b; } } diff --git a/Source/Glide64/TexModCI.h b/Source/Glide64/TexModCI.h index 41e90f717..a9543e26d 100644 --- a/Source/Glide64/TexModCI.h +++ b/Source/Glide64/TexModCI.h @@ -56,9 +56,9 @@ static void mod_tex_inter_color_using_factor_CI (uint32_t color, uint32_t factor r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = (uint8_t)(min(255, percent_i * r + percent * cr)); - g = (uint8_t)(min(255, percent_i * g + percent * cg)); - b = (uint8_t)(min(255, percent_i * b + percent * cb)); + r = (uint8_t)(minval(255, percent_i * r + percent * cr)); + g = (uint8_t)(minval(255, percent_i * g + percent * cg)); + b = (uint8_t)(minval(255, percent_i * b + percent * cb)); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -90,9 +90,9 @@ static void mod_tex_inter_col_using_col1_CI (uint32_t color0, uint32_t color1) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = (uint8_t)(min(255, percent_r_i * r + percent_r * cr)); - g = (uint8_t)(min(255, percent_g_i * g + percent_g * cg)); - b = (uint8_t)(min(255, percent_b_i * b + percent_b * cb)); + r = (uint8_t)(minval(255, percent_r_i * r + percent_r * cr)); + g = (uint8_t)(minval(255, percent_g_i * g + percent_g * cg)); + b = (uint8_t)(minval(255, percent_b_i * b + percent_b * cb)); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -118,10 +118,10 @@ static void mod_full_color_sub_tex_CI (uint32_t color) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - a = max(0, ca - a); - r = max(0, cr - r); - g = max(0, cg - g); - b = max(0, cb - b); + a = maxval(0, ca - a); + r = maxval(0, cr - r); + g = maxval(0, cg - g); + b = maxval(0, cb - b); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -150,9 +150,9 @@ static void mod_col_inter_col1_using_tex_CI (uint32_t color0, uint32_t color1) percent_r = ((col&0xF800) >> 11) / 31.0f; percent_g = ((col&0x07C0) >> 6) / 31.0f; percent_b = ((col&0x003E) >> 1) / 31.0f; - r = (uint8_t)(min((1.0f-percent_r) * cr0 + percent_r * cr1, 255)); - g = (uint8_t)(min((1.0f-percent_g) * cg0 + percent_g * cg1, 255)); - b = (uint8_t)(min((1.0f-percent_b) * cb0 + percent_b * cb1, 255)); + r = (uint8_t)(minval((1.0f-percent_r) * cr0 + percent_r * cr1, 255)); + g = (uint8_t)(minval((1.0f-percent_g) * cg0 + percent_g * cg1, 255)); + b = (uint8_t)(minval((1.0f-percent_b) * cb0 + percent_b * cb1, 255)); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -216,9 +216,9 @@ static void mod_tex_scale_col_add_col_CI (uint32_t color0, uint32_t color1) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = (uint8_t)(min(255, percent_r * r + cr)); - g = (uint8_t)(min(255, percent_g * g + cg)); - b = (uint8_t)(min(255, percent_b * b + cb)); + r = (uint8_t)(minval(255, percent_r * r + cr)); + g = (uint8_t)(minval(255, percent_g * g + cg)); + b = (uint8_t)(minval(255, percent_b * b + cb)); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -243,9 +243,9 @@ static void mod_tex_add_col_CI (uint32_t color) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = min(cr + r, 255); - g = min(cg + g, 255); - b = min(cb + b, 255); + r = minval(cr + r, 255); + g = minval(cg + g, 255); + b = minval(cb + b, 255); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -270,9 +270,9 @@ static void mod_tex_sub_col_CI (uint32_t color) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = max(r - cr, 0); - g = max(g - cg, 0); - b = max(b - cb, 0); + r = maxval(r - cr, 0); + g = maxval(g - cg, 0); + b = maxval(b - cb, 0); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | @@ -340,9 +340,9 @@ static void mod_col_inter_tex_using_col1_CI (uint32_t color0, uint32_t color1) r = (uint8_t)((float)((col&0xF800) >> 11) / 31.0f * 255.0f); g = (uint8_t)((float)((col&0x07C0) >> 6) / 31.0f * 255.0f); b = (uint8_t)((float)((col&0x003E) >> 1) / 31.0f * 255.0f); - r = (uint8_t)(min(255, percent_r * r + percent_r_i * cr)); - g = (uint8_t)(min(255, percent_g * g + percent_g_i * cg)); - b = (uint8_t)(min(255, percent_b * b + percent_b_i * cb)); + r = (uint8_t)(minval(255, percent_r * r + percent_r_i * cr)); + g = (uint8_t)(minval(255, percent_g * g + percent_g_i * cg)); + b = (uint8_t)(minval(255, percent_b * b + percent_b_i * cb)); rdp.pal_8[i] = (uint16_t)(((uint16_t)(r >> 3) << 11) | ((uint16_t)(g >> 3) << 6) | ((uint16_t)(b >> 3) << 1) | diff --git a/Source/Glide64/Util.cpp b/Source/Glide64/Util.cpp index 96bde05e4..911e927e7 100644 --- a/Source/Glide64/Util.cpp +++ b/Source/Glide64/Util.cpp @@ -311,7 +311,7 @@ void draw_tri(VERTEX **vtx, uint16_t linew) double fdz = fabs(fdzdx) + fabs(fdzdy); if ((settings.hacks & hack_Zelda) && (rdp.rm & 0x800)) fdz *= 4.0; // Decal mode in Zelda sometimes needs mutiplied deltaZ to work correct, e.g. roads - deltaZ = max(8, (int)fdz); + deltaZ = maxval(8, (int)fdz); } dzdx = (int)(fdzdx * 65536.0); } @@ -336,7 +336,7 @@ void draw_tri(VERTEX **vtx, uint16_t linew) { if (rdp.geom_mode & 0x00000004) // flat shading { - int flag = min(2, (rdp.cmd1 >> 24) & 3); + int flag = minval(2, (rdp.cmd1 >> 24) & 3); v->a = vtx[flag]->a; v->b = vtx[flag]->b; v->g = vtx[flag]->g; @@ -486,11 +486,11 @@ void draw_tri(VERTEX **vtx, uint16_t linew) int index, i, j, min_256, max_256, cur_256, left_256, right_256; float percent; - min_256 = min((int)vtx[0]->u0, (int)vtx[1]->u0); // bah, don't put two mins on one line - min_256 = min(min_256, (int)vtx[2]->u0) >> 8; // or it will be calculated twice + min_256 = minval((int)vtx[0]->u0, (int)vtx[1]->u0); // bah, don't put two mins on one line + min_256 = minval(min_256, (int)vtx[2]->u0) >> 8; // or it will be calculated twice - max_256 = max((int)vtx[0]->u0, (int)vtx[1]->u0); // not like it makes much difference - max_256 = max(max_256, (int)vtx[2]->u0) >> 8; // anyway :P + max_256 = maxval((int)vtx[0]->u0, (int)vtx[1]->u0); // not like it makes much difference + max_256 = maxval(max_256, (int)vtx[2]->u0) >> 8; // anyway :P for (cur_256 = min_256; cur_256 <= max_256; cur_256++) { @@ -1012,11 +1012,11 @@ static void CalculateLOD(VERTEX *v, int n) lodFactor = lodFactor / n; } int ilod = (int)lodFactor; - int lod_tile = min((int)(log10f((float)ilod) / log10f(2.0f)), rdp.cur_tile + rdp.mipmap_level); + int lod_tile = minval((int)(log10f((float)ilod) / log10f(2.0f)), rdp.cur_tile + rdp.mipmap_level); float lod_fraction = 1.0f; if (lod_tile < rdp.cur_tile + rdp.mipmap_level) { - lod_fraction = max((float)modf(lodFactor / pow(2., lod_tile), &intptr), rdp.prim_lodmin / 255.0f); + lod_fraction = maxval((float)modf(lodFactor / pow(2., lod_tile), &intptr), rdp.prim_lodmin / 255.0f); } float detailmax; if (cmb.dc0_detailmax < 0.5f) @@ -1586,12 +1586,12 @@ static void render_tri(uint16_t linew, int old_interpolate) { for (i = 0; i < n; i++) { - rdp.vtxbuf[i].f = 1.0f / max(4.0f, rdp.vtxbuf[i].f); + rdp.vtxbuf[i].f = 1.0f / maxval(4.0f, rdp.vtxbuf[i].f); } } else if (rdp.fog_mode == RDP::fog_blend) { - float fog = 1.0f / max(1, rdp.fog_color & 0xFF); + float fog = 1.0f / maxval(1, rdp.fog_color & 0xFF); for (i = 0; i < n; i++) { rdp.vtxbuf[i].f = fog; @@ -1599,7 +1599,7 @@ static void render_tri(uint16_t linew, int old_interpolate) } else if (rdp.fog_mode == RDP::fog_blend_inverse) { - float fog = 1.0f / max(1, (~rdp.fog_color) & 0xFF); + float fog = 1.0f / maxval(1, (~rdp.fog_color) & 0xFF); for (i = 0; i < n; i++) { rdp.vtxbuf[i].f = fog; @@ -1782,10 +1782,10 @@ void update_scissor() rdp.update ^= UPDATE_SCISSOR; // KILL the floating point error with 0.01f - rdp.scissor.ul_x = (uint32_t)max(min((rdp.scissor_o.ul_x * rdp.scale_x + rdp.offset_x + 0.01f), settings.res_x), 0); - rdp.scissor.lr_x = (uint32_t)max(min((rdp.scissor_o.lr_x * rdp.scale_x + rdp.offset_x + 0.01f), settings.res_x), 0); - rdp.scissor.ul_y = (uint32_t)max(min((rdp.scissor_o.ul_y * rdp.scale_y + rdp.offset_y + 0.01f), settings.res_y), 0); - rdp.scissor.lr_y = (uint32_t)max(min((rdp.scissor_o.lr_y * rdp.scale_y + rdp.offset_y + 0.01f), settings.res_y), 0); + rdp.scissor.ul_x = (uint32_t)maxval(minval((rdp.scissor_o.ul_x * rdp.scale_x + rdp.offset_x + 0.01f), settings.res_x), 0); + rdp.scissor.lr_x = (uint32_t)maxval(minval((rdp.scissor_o.lr_x * rdp.scale_x + rdp.offset_x + 0.01f), settings.res_x), 0); + rdp.scissor.ul_y = (uint32_t)maxval(minval((rdp.scissor_o.ul_y * rdp.scale_y + rdp.offset_y + 0.01f), settings.res_y), 0); + rdp.scissor.lr_y = (uint32_t)maxval(minval((rdp.scissor_o.lr_y * rdp.scale_y + rdp.offset_y + 0.01f), settings.res_y), 0); //grClipWindow specifies the hardware clipping window. Any pixels outside the clipping window are rejected. //Values are inclusive for minimum x and y values and exclusive for maximum x and y values. // grClipWindow (rdp.scissor.ul_x?rdp.scissor.ul_x+1:0, rdp.scissor.ul_y?rdp.scissor.ul_y+1:0, rdp.scissor.lr_x, rdp.scissor.lr_y); @@ -2095,10 +2095,10 @@ void update() float scale_x = (float)fabs(rdp.view_scale[0]); float scale_y = (float)fabs(rdp.view_scale[1]); - rdp.clip_min_x = max((rdp.view_trans[0] - scale_x + rdp.offset_x) / rdp.clip_ratio, 0.0f); - rdp.clip_min_y = max((rdp.view_trans[1] - scale_y + rdp.offset_y) / rdp.clip_ratio, 0.0f); - rdp.clip_max_x = min((rdp.view_trans[0] + scale_x + rdp.offset_x) * rdp.clip_ratio, settings.res_x); - rdp.clip_max_y = min((rdp.view_trans[1] + scale_y + rdp.offset_y) * rdp.clip_ratio, settings.res_y); + rdp.clip_min_x = maxval((rdp.view_trans[0] - scale_x + rdp.offset_x) / rdp.clip_ratio, 0.0f); + rdp.clip_min_y = maxval((rdp.view_trans[1] - scale_y + rdp.offset_y) / rdp.clip_ratio, 0.0f); + rdp.clip_max_x = minval((rdp.view_trans[0] + scale_x + rdp.offset_x) * rdp.clip_ratio, settings.res_x); + rdp.clip_max_y = minval((rdp.view_trans[1] + scale_y + rdp.offset_y) * rdp.clip_ratio, settings.res_y); FRDP(" |- viewport - (%d, %d, %d, %d)\n", (uint32_t)rdp.clip_min_x, (uint32_t)rdp.clip_min_y, (uint32_t)rdp.clip_max_x, (uint32_t)rdp.clip_max_y); if (!rdp.scissor_set) diff --git a/Source/Glide64/rdp.cpp b/Source/Glide64/rdp.cpp index 8a824d560..773cafec3 100644 --- a/Source/Glide64/rdp.cpp +++ b/Source/Glide64/rdp.cpp @@ -479,8 +479,8 @@ static void CopyFrameBuffer(GrBuffer_t buffer = GR_BUFFER_BACKBUFFER) } else { - float scale_x = (settings.scr_res_x - rdp.offset_x*2.0f) / max(width, rdp.vi_width); - float scale_y = (settings.scr_res_y - rdp.offset_y*2.0f) / max(height, rdp.vi_height); + float scale_x = (settings.scr_res_x - rdp.offset_x*2.0f) / maxval(width, rdp.vi_width); + float scale_y = (settings.scr_res_y - rdp.offset_y*2.0f) / maxval(height, rdp.vi_height); FRDP("width: %d, height: %d, ul_y: %d, lr_y: %d, scale_x: %f, scale_y: %f, ci_width: %d, ci_height: %d\n", width, height, rdp.ci_upper_bound, rdp.ci_lower_bound, scale_x, scale_y, rdp.ci_width, rdp.ci_height); GrLfbInfo_t info; @@ -582,7 +582,7 @@ EXPORT void CALL ProcessDList(void) { hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0); -} + } #endif LOG("ProcessDList ()\n"); @@ -642,7 +642,7 @@ EXPORT void CALL ProcessDList(void) rdp.model_i = 0; // 0 matrices so far in stack //stack_size can be less then 32! Important for Silicon Vally. Thanks Orkin! - rdp.model_stack_size = min(32, (*(uint32_t*)(gfx.DMEM + 0x0FE4)) >> 6); + rdp.model_stack_size = minval(32, (*(uint32_t*)(gfx.DMEM + 0x0FE4)) >> 6); if (rdp.model_stack_size == 0) rdp.model_stack_size = 32; rdp.Persp_en = TRUE; @@ -784,7 +784,7 @@ EXPORT void CALL ProcessDList(void) to_fullscreen = TRUE; } return; - } + } #endif if (fb_emulation_enabled) @@ -807,7 +807,7 @@ EXPORT void CALL ProcessDList(void) CI_SET = FALSE; } LRDP("ProcessDList end\n"); - } +} // undef - undefined instruction, always ignore static void undef() @@ -995,17 +995,17 @@ static void rdp_texrect() float ul_x, ul_y, lr_x, lr_y; if (rdp.cycle_mode == 2) { - ul_x = max(0.0f, (short)((rdp.cmd1 & 0x00FFF000) >> 14)); - ul_y = max(0.0f, (short)((rdp.cmd1 & 0x00000FFF) >> 2)); - lr_x = max(0.0f, (short)((rdp.cmd0 & 0x00FFF000) >> 14)); - lr_y = max(0.0f, (short)((rdp.cmd0 & 0x00000FFF) >> 2)); + ul_x = maxval(0.0f, (short)((rdp.cmd1 & 0x00FFF000) >> 14)); + ul_y = maxval(0.0f, (short)((rdp.cmd1 & 0x00000FFF) >> 2)); + lr_x = maxval(0.0f, (short)((rdp.cmd0 & 0x00FFF000) >> 14)); + lr_y = maxval(0.0f, (short)((rdp.cmd0 & 0x00000FFF) >> 2)); } else { - ul_x = max(0.0f, ((short)((rdp.cmd1 & 0x00FFF000) >> 12)) / 4.0f); - ul_y = max(0.0f, ((short)(rdp.cmd1 & 0x00000FFF)) / 4.0f); - lr_x = max(0.0f, ((short)((rdp.cmd0 & 0x00FFF000) >> 12)) / 4.0f); - lr_y = max(0.0f, ((short)(rdp.cmd0 & 0x00000FFF)) / 4.0f); + ul_x = maxval(0.0f, ((short)((rdp.cmd1 & 0x00FFF000) >> 12)) / 4.0f); + ul_y = maxval(0.0f, ((short)(rdp.cmd1 & 0x00000FFF)) / 4.0f); + lr_x = maxval(0.0f, ((short)((rdp.cmd0 & 0x00FFF000) >> 12)) / 4.0f); + lr_y = maxval(0.0f, ((short)(rdp.cmd0 & 0x00000FFF)) / 4.0f); } if (ul_x >= lr_x) @@ -1420,9 +1420,9 @@ static void rdp_texrect() { float fog; if (rdp.fog_mode == RDP::fog_blend) - fog = 1.0f / max(1, rdp.fog_color & 0xFF); + fog = 1.0f / maxval(1, rdp.fog_color & 0xFF); else - fog = 1.0f / max(1, (~rdp.fog_color) & 0xFF); + fog = 1.0f / maxval(1, (~rdp.fog_color) & 0xFF); for (i = 0; i < n_vertices; i++) { vptr[i].f = fog; @@ -1531,10 +1531,10 @@ static void rdp_setconvert() static void rdp_setscissor() { // clipper resolution is 320x240, scale based on computer resolution - rdp.scissor_o.ul_x = /*min(*/(uint32_t)(((rdp.cmd0 & 0x00FFF000) >> 14))/*, 320)*/; - rdp.scissor_o.ul_y = /*min(*/(uint32_t)(((rdp.cmd0 & 0x00000FFF) >> 2))/*, 240)*/; - rdp.scissor_o.lr_x = /*min(*/(uint32_t)(((rdp.cmd1 & 0x00FFF000) >> 14))/*, 320)*/; - rdp.scissor_o.lr_y = /*min(*/(uint32_t)(((rdp.cmd1 & 0x00000FFF) >> 2))/*, 240)*/; + rdp.scissor_o.ul_x = /*minval(*/(uint32_t)(((rdp.cmd0 & 0x00FFF000) >> 14))/*, 320)*/; + rdp.scissor_o.ul_y = /*minval(*/(uint32_t)(((rdp.cmd0 & 0x00000FFF) >> 2))/*, 240)*/; + rdp.scissor_o.lr_x = /*minval(*/(uint32_t)(((rdp.cmd1 & 0x00FFF000) >> 14))/*, 320)*/; + rdp.scissor_o.lr_y = /*minval(*/(uint32_t)(((rdp.cmd1 & 0x00000FFF) >> 2))/*, 240)*/; rdp.ci_upper_bound = rdp.scissor_o.ul_y; rdp.ci_lower_bound = rdp.scissor_o.lr_y; @@ -2145,8 +2145,8 @@ static void rdp_loadtile() LOAD_TILE_INFO &info = rdp.load_info[rdp.tiles[tile].t_mem]; info.tile_ul_s = ul_s; info.tile_ul_t = ul_t; - info.tile_width = (rdp.tiles[tile].mask_s ? min((uint16_t)width, 1 << rdp.tiles[tile].mask_s) : (uint16_t)width); - info.tile_height = (rdp.tiles[tile].mask_t ? min((uint16_t)height, 1 << rdp.tiles[tile].mask_t) : (uint16_t)height); + info.tile_width = (rdp.tiles[tile].mask_s ? minval((uint16_t)width, 1 << rdp.tiles[tile].mask_s) : (uint16_t)width); + info.tile_height = (rdp.tiles[tile].mask_t ? minval((uint16_t)height, 1 << rdp.tiles[tile].mask_t) : (uint16_t)height); if (settings.hacks&hack_MK64) { if (info.tile_width % 2) info.tile_width--; @@ -2275,10 +2275,10 @@ static void rdp_fillrect() } //if (settings.frame_buffer&fb_depth_clear) { - ul_x = min(max(ul_x, rdp.scissor_o.ul_x), rdp.scissor_o.lr_x); - lr_x = min(max(lr_x, rdp.scissor_o.ul_x), rdp.scissor_o.lr_x); - ul_y = min(max(ul_y, rdp.scissor_o.ul_y), rdp.scissor_o.lr_y); - lr_y = min(max(lr_y, rdp.scissor_o.ul_y), rdp.scissor_o.lr_y); + ul_x = minval(maxval(ul_x, rdp.scissor_o.ul_x), rdp.scissor_o.lr_x); + lr_x = minval(maxval(lr_x, rdp.scissor_o.ul_x), rdp.scissor_o.lr_x); + ul_y = minval(maxval(ul_y, rdp.scissor_o.ul_y), rdp.scissor_o.lr_y); + lr_y = minval(maxval(lr_y, rdp.scissor_o.ul_y), rdp.scissor_o.lr_y); uint32_t zi_width_in_dwords = rdp.ci_width >> 1; ul_x >>= 1; lr_x >>= 1; @@ -2334,10 +2334,10 @@ static void rdp_fillrect() rdp.scissor.lr_y); // KILL the floating point error with 0.01f - wxInt32 s_ul_x = (uint32_t)min(max(ul_x * rdp.scale_x + rdp.offset_x + 0.01f, rdp.scissor.ul_x), rdp.scissor.lr_x); - wxInt32 s_lr_x = (uint32_t)min(max(lr_x * rdp.scale_x + rdp.offset_x + 0.01f, rdp.scissor.ul_x), rdp.scissor.lr_x); - wxInt32 s_ul_y = (uint32_t)min(max(ul_y * rdp.scale_y + rdp.offset_y + 0.01f, rdp.scissor.ul_y), rdp.scissor.lr_y); - wxInt32 s_lr_y = (uint32_t)min(max(lr_y * rdp.scale_y + rdp.offset_y + 0.01f, rdp.scissor.ul_y), rdp.scissor.lr_y); + wxInt32 s_ul_x = (uint32_t)minval(maxval(ul_x * rdp.scale_x + rdp.offset_x + 0.01f, rdp.scissor.ul_x), rdp.scissor.lr_x); + wxInt32 s_lr_x = (uint32_t)minval(maxval(lr_x * rdp.scale_x + rdp.offset_x + 0.01f, rdp.scissor.ul_x), rdp.scissor.lr_x); + wxInt32 s_ul_y = (uint32_t)minval(maxval(ul_y * rdp.scale_y + rdp.offset_y + 0.01f, rdp.scissor.ul_y), rdp.scissor.lr_y); + wxInt32 s_lr_y = (uint32_t)minval(maxval(lr_y * rdp.scale_y + rdp.offset_y + 0.01f, rdp.scissor.ul_y), rdp.scissor.lr_y); if (s_lr_x < 0) s_lr_x = 0; if (s_lr_y < 0) s_lr_y = 0; @@ -2495,7 +2495,7 @@ static void rdp_setprimcolor() { rdp.prim_color = rdp.cmd1; rdp.prim_lodmin = (rdp.cmd0 >> 8) & 0xFF; - rdp.prim_lodfrac = max(rdp.cmd0 & 0xFF, rdp.prim_lodmin); + rdp.prim_lodfrac = maxval(rdp.cmd0 & 0xFF, rdp.prim_lodmin); rdp.update |= UPDATE_COMBINE; FRDP("setprimcolor: %08lx, lodmin: %d, lodfrac: %d\n", rdp.cmd1, rdp.prim_lodmin, @@ -2925,7 +2925,7 @@ static void rdp_setcolorimage() if (rdp.zimg == rdp.cimg) { rdp.zi_width = rdp.ci_width; - // int zi_height = min((int)rdp.zi_width*3/4, (int)rdp.vi_height); + // int zi_height = minval((int)rdp.zi_width*3/4, (int)rdp.vi_height); // rdp.zi_words = rdp.zi_width * zi_height; } uint32_t format = (rdp.cmd0 >> 21) & 0x7; @@ -3202,10 +3202,10 @@ EXPORT void CALL FBWrite(uint32_t addr, uint32_t /*size*/) uint32_t shift_l = (a - rdp.cimg) >> 1; uint32_t shift_r = shift_l + 2; - d_ul_x = min(d_ul_x, shift_l%rdp.ci_width); - d_ul_y = min(d_ul_y, shift_l / rdp.ci_width); - d_lr_x = max(d_lr_x, shift_r%rdp.ci_width); - d_lr_y = max(d_lr_y, shift_r / rdp.ci_width); + d_ul_x = minval(d_ul_x, shift_l%rdp.ci_width); + d_ul_y = minval(d_ul_y, shift_l / rdp.ci_width); + d_lr_x = maxval(d_lr_x, shift_r%rdp.ci_width); + d_lr_y = maxval(d_lr_y, shift_r / rdp.ci_width); } /************************************************************************ diff --git a/Source/Glide64/rdp.h b/Source/Glide64/rdp.h index 50862fcea..bda3aa34a 100644 --- a/Source/Glide64/rdp.h +++ b/Source/Glide64/rdp.h @@ -839,11 +839,11 @@ extern const char *CIStatus[]; * The only solution is to include first, before or * before defining the below macros (or just don't use ). */ -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef maxval +#define maxval(a, b) (((a) > (b)) ? (a) : (b)) #endif -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) +#ifndef minval +#define minval(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef TRUE @@ -907,7 +907,7 @@ __inline void CalculateFog (VERTEX *v) if (v->w < 0.0f) v->f = 0.0f; else - v->f = min(255.0f, max(0.0f, v->z_w * rdp.fog_multiplier + rdp.fog_offset)); + v->f = minval(255.0f, maxval(0.0f, v->z_w * rdp.fog_multiplier + rdp.fog_offset)); v->a = (uint8_t)v->f; } else diff --git a/Source/Glide64/ucode06.h b/Source/Glide64/ucode06.h index 4780b4192..e4af80d3f 100644 --- a/Source/Glide64/ucode06.h +++ b/Source/Glide64/ucode06.h @@ -262,8 +262,8 @@ void DrawDepthImage(const DRAWIMAGE & d) float scale_y_src = 1.0f / rdp.scale_y; int src_width = d.imageW; int src_height = d.imageH; - int dst_width = min(int(src_width*scale_x_dst), (int)settings.scr_res_x); - int dst_height = min(int(src_height*scale_y_dst), (int)settings.scr_res_y); + int dst_width = minval(int(src_width*scale_x_dst), (int)settings.scr_res_x); + int dst_height = minval(int(src_height*scale_y_dst), (int)settings.scr_res_y); uint16_t * src = (uint16_t*)(gfx.RDRAM + d.imagePtr); uint16_t * dst = new uint16_t[dst_width*dst_height]; for (int y = 0; y < dst_height; y++) @@ -447,7 +447,7 @@ void DrawImage(DRAWIMAGE & d) else if (d.scaleX == 1.0f && d.scaleY == 1.0f) grClipWindow(rdp.scissor.ul_x, rdp.scissor.ul_y, rdp.scissor.lr_x, rdp.scissor.lr_y); else - grClipWindow(rdp.scissor.ul_x, rdp.scissor.ul_y, min(rdp.scissor.lr_x, (uint32_t)((d.frameX + d.imageW / d.scaleX + 0.5f)*rdp.scale_x)), min(rdp.scissor.lr_y, (uint32_t)((d.frameY + d.imageH / d.scaleY + 0.5f)*rdp.scale_y))); + grClipWindow(rdp.scissor.ul_x, rdp.scissor.ul_y, minval(rdp.scissor.lr_x, (uint32_t)((d.frameX + d.imageW / d.scaleX + 0.5f)*rdp.scale_x)), minval(rdp.scissor.lr_y, (uint32_t)((d.frameY + d.imageH / d.scaleY + 0.5f)*rdp.scale_y))); rdp.update |= UPDATE_SCISSOR; // Texture () @@ -486,7 +486,7 @@ void DrawImage(DRAWIMAGE & d) cur_u = min_256_u + 1; // calculate intersection with this point - nlr_v = min(min(cur_wrap_v*d.imageH, (cur_v << y_shift)), lr_v); + nlr_v = minval(minval(cur_wrap_v*d.imageH, (cur_v << y_shift)), lr_v); nlr_y = my * nlr_v + by; nul_u = ul_u; @@ -498,7 +498,7 @@ void DrawImage(DRAWIMAGE & d) while (1) { // calculate intersection with this point - nlr_u = min(min(cur_wrap_u*d.imageW, (cur_u << x_shift)), lr_u); + nlr_u = minval(minval(cur_wrap_u*d.imageW, (cur_u << x_shift)), lr_u); nlr_x = mx * nlr_u + bx; // ** Load the texture, constant portions have been set above @@ -657,8 +657,8 @@ void DrawHiresImage(DRAWIMAGE & d, int screensize = FALSE) lr_u *= rdp.tbuff_tex->u_scale; ul_v *= rdp.tbuff_tex->v_scale; lr_v *= rdp.tbuff_tex->v_scale; - ul_u = max(0.15f, ul_u); - ul_v = max(0.15f, ul_v); + ul_u = maxval(0.15f, ul_u); + ul_v = maxval(0.15f, ul_v); if (lr_x > rdp.scissor.lr_x) lr_x = (float)rdp.scissor.lr_x; if (lr_y > rdp.scissor.lr_y) lr_y = (float)rdp.scissor.lr_y; } @@ -796,11 +796,11 @@ static void draw_split_triangle(VERTEX **vtx) int index, i, j, min_256, max_256, cur_256, left_256, right_256; float percent; - min_256 = min((int)vtx[0]->u0, (int)vtx[1]->u0); // bah, don't put two mins on one line - min_256 = min(min_256, (int)vtx[2]->u0) >> 8; // or it will be calculated twice + min_256 = minval((int)vtx[0]->u0, (int)vtx[1]->u0); // bah, don't put two mins on one line + min_256 = minval(min_256, (int)vtx[2]->u0) >> 8; // or it will be calculated twice - max_256 = max((int)vtx[0]->u0, (int)vtx[1]->u0); // not like it makes much difference - max_256 = max(max_256, (int)vtx[2]->u0) >> 8; // anyway :P + max_256 = maxval((int)vtx[0]->u0, (int)vtx[1]->u0); // not like it makes much difference + max_256 = maxval(max_256, (int)vtx[2]->u0) >> 8; // anyway :P for (cur_256 = min_256; cur_256 <= max_256; cur_256++) { diff --git a/Source/Glide64/ucodeFB.h b/Source/Glide64/ucodeFB.h index fe2cc6dad..39bd6e6e0 100644 --- a/Source/Glide64/ucodeFB.h +++ b/Source/Glide64/ucodeFB.h @@ -156,7 +156,7 @@ static void fb_rect() int diff = abs((int)rdp.frame_buffers[rdp.ci_count-1].width - width); if (diff < 4) { - uint32_t lr_y = min(rdp.scissor_o.lr_y, (rdp.cmd0 & 0xFFF) >> 2); + uint32_t lr_y = minval(rdp.scissor_o.lr_y, (rdp.cmd0 & 0xFFF) >> 2); if (rdp.frame_buffers[rdp.ci_count-1].height < lr_y) { FRDP("fb_rect. ul_x: %d, lr_x: %d, fb_height: %d -> %d\n", ul_x, lr_x, rdp.frame_buffers[rdp.ci_count-1].height, lr_y); @@ -380,7 +380,7 @@ static void fb_setcolorimage() { if (rdp.cimg == rdp.main_ci) //switched to main fb again { - cur_fb.height = max(cur_fb.height, rdp.frame_buffers[rdp.main_ci_index].height); + cur_fb.height = maxval(cur_fb.height, rdp.frame_buffers[rdp.main_ci_index].height); rdp.main_ci_index = rdp.ci_count; rdp.main_ci_end = rdp.cimg + ((cur_fb.width * cur_fb.height) << cur_fb.size >> 1); cur_fb.status = ci_main;