diff --git a/include/asm/mymath.h b/include/asm/mymath.h index 8c543b88..449f733d 100644 --- a/include/asm/mymath.h +++ b/include/asm/mymath.h @@ -14,5 +14,8 @@ SLONG math_ATan(SLONG i); SLONG math_ATan2(SLONG i, SLONG j); SLONG math_Mul(SLONG i, SLONG j); SLONG math_Div(SLONG i, SLONG j); +SLONG math_Round(SLONG i); +SLONG math_Ceil(SLONG i); +SLONG math_Floor(SLONG i); #endif diff --git a/src/asm/asmy.y b/src/asm/asmy.y index cb7241f9..fa00cc5f 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -412,6 +412,10 @@ void if_skip_to_endc( void ) %left T_OP_ATAN2 %left T_OP_FDIV %left T_OP_FMUL +%left T_OP_ROUND +%left T_OP_CEIL +%left T_OP_FLOOR + %left T_OP_STRCMP %left T_OP_STRIN @@ -953,6 +957,9 @@ relocconst : T_ID { rpn_Bank(&$$,$3); $$.nVal = 0; } | T_OP_DEF { oDontExpandStrings=1; } '(' T_ID ')' { rpn_Number(&$$,sym_isConstDefined($4)); oDontExpandStrings=0; } + | T_OP_ROUND '(' const ')' { rpn_Number(&$$,math_Round($3)); } + | T_OP_CEIL '(' const ')' { rpn_Number(&$$,math_Ceil($3)); } + | T_OP_FLOOR '(' const ')' { rpn_Number(&$$,math_Floor($3)); } | T_OP_FDIV '(' const ',' const ')' { rpn_Number(&$$,math_Div($3,$5)); } | T_OP_FMUL '(' const ',' const ')' { rpn_Number(&$$,math_Mul($3,$5)); } | T_OP_SIN '(' const ')' { rpn_Number(&$$,math_Sin($3)); } @@ -1006,6 +1013,9 @@ const : T_ID { $$ = sym_GetConstantValue($1); } | T_OP_ADD const %prec NEG { $$ = +$2; } | T_OP_SUB const %prec NEG { $$ = -$2; } | T_OP_NOT const %prec NEG { $$ = 0xFFFFFFFF^$2; } + | T_OP_ROUND '(' const ')' { $$ = math_Round($3); } + | T_OP_CEIL '(' const ')' { $$ = math_Ceil($3); } + | T_OP_FLOOR '(' const ')' { $$ = math_Floor($3); } | T_OP_FDIV '(' const ',' const ')' { $$ = math_Div($3,$5); } | T_OP_FMUL '(' const ',' const ')' { $$ = math_Mul($3,$5); } | T_OP_SIN '(' const ')' { $$ = math_Sin($3); } diff --git a/src/asm/globlex.c b/src/asm/globlex.c index 3719755a..c30a76b7 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -267,6 +267,9 @@ struct sLexInitString staticstrings[] = { {"bank", T_OP_BANK}, + {"round", T_OP_ROUND}, + {"ceil", T_OP_CEIL}, + {"floor", T_OP_FLOOR}, {"div", T_OP_FDIV}, {"mul", T_OP_FMUL}, {"sin", T_OP_SIN}, diff --git a/src/asm/math.c b/src/asm/math.c index d5e2f280..c47fbb2f 100644 --- a/src/asm/math.c +++ b/src/asm/math.c @@ -155,4 +155,37 @@ SLONG math_Div(SLONG i, SLONG j) { return (double2fix(fix2double(i) / fix2double(j))); +}/* + * RGBAsm - MATH.C (Fixedpoint math routines) + * + * Round + * + */ + +SLONG +math_Round(SLONG i) +{ + return double2fix(round(fix2double(i))); +}/* + * RGBAsm - MATH.C (Fixedpoint math routines) + * + * Ceil + * + */ + +SLONG +math_Ceil(SLONG i) +{ + return double2fix(ceil(fix2double(i))); +}/* + * RGBAsm - MATH.C (Fixedpoint math routines) + * + * Floor + * + */ + +SLONG +math_Floor(SLONG i) +{ + return double2fix(floor(fix2double(i))); }