diff --git a/basic/sources/commands/base/clear.asm b/basic/sources/commands/base/clear.asm index d3e04ada..47345741 100644 --- a/basic/sources/commands/base/clear.asm +++ b/basic/sources/commands/base/clear.asm @@ -100,6 +100,14 @@ ClearCodeSetMemoryA: .DoSendMessage .byte 10,1 .DoWaitMessage + ; + ; Reset to Degrees + ; + lda #1 + sta ControlParameters+0 + .DoSendMessage + .byte 4,35 + .DoWaitMessage ply rts diff --git a/basic/test.bsc b/basic/test.bsc index 4c4810b3..afdadcdc 100644 --- a/basic/test.bsc +++ b/basic/test.bsc @@ -1 +1,24 @@ -10 print 1.2 + +while peek($FF00):wend +poke $FF04,0 +poke $FF01,35 +poke $FF00,4 +while peek($FF00):wend + +a = 3.1415/4 +s = sin(a) +t = tan(a) +print a;" ";s;" ";t;" ";atan(t) +print + +while peek($FF00):wend +poke $FF04,1 +poke $FF01,35 +poke $FF00,4 +while peek($FF00):wend + +a = 45 +s = sin(a) +t = tan(a) +print a;" ";s;" ";t;" ";atan(t) + diff --git a/documents/release/source/api.tex b/documents/release/source/api.tex index 9f2273c2..5b3561a6 100644 --- a/documents/release/source/api.tex +++ b/documents/release/source/api.tex @@ -22,7 +22,7 @@ \title{Neo6502 Assembly - Messaging API} \author{Paul Robson \\ Bill Auger} -\date{2024-04-03} +\date{2024-04-04} \renewcommand{\familydefault}{\sfdefault} \graphicspath{ {./img/} % WRT local editor (eg: texworks) @@ -750,16 +750,16 @@ \section{API Functions}\label{api-functions} Register1 := square root(Register 1) } \ApiFnRow{19}{Sine}{ -Register1 := sine(Register 1) angles in degrees +Register1 := sine(Register 1) angles in degrees/radians } \ApiFnRow{20}{Cosine}{ -Register1 := cosine(Register 1) angles in degrees +Register1 := cosine(Register 1) angles in degrees/radians } \ApiFnRow{21}{Tangent}{ -Register1 := tangent(Register 1) angles in degrees +Register1 := tangent(Register 1) angles in degrees/radians } \ApiFnRow{22}{Arctangent}{ -Register1 := arctangent(Register 1) angles in degrees +Register1 := arctangent(Register 1) angles in degrees/radians } \ApiFnRow{23}{Exponent}{ Register1 := e to the power of Register 1 @@ -788,6 +788,9 @@ \section{API Functions}\label{api-functions} \ApiFnRow{34}{Number to String}{ Convert the constant in Register1 to a length prefixed string which is stored at \Param{4,5} } +\ApiFnRow{35}{Set Degree/Radian Mode}{ +Sets the use of degrees (the default) when non zero, radians when zero. +} \end{longtable*} \pagebreak \begin{longtable*}{ | c | l | p{12cm} | } diff --git a/firmware/common/config/defines.inc b/firmware/common/config/defines.inc deleted file mode 100644 index 519e04e6..00000000 --- a/firmware/common/config/defines.inc +++ /dev/null @@ -1,2 +0,0 @@ -#define FROMRADIANS(n) ((n) * 180.0 / M_PI) -#define TORADIANS(n) ((n) * M_PI / 180.0) diff --git a/firmware/common/config/dispatch.config b/firmware/common/config/dispatch.config index 45d415ee..3517d8c5 100644 --- a/firmware/common/config/dispatch.config +++ b/firmware/common/config/dispatch.config @@ -10,8 +10,6 @@ // *************************************************************************************** // *************************************************************************************** -include defines.inc - include system/group1_system.inc include display/group2_console.inc include system/group3_fileio.inc diff --git a/firmware/common/config/mathematics/group4_other.inc b/firmware/common/config/mathematics/group4_other.inc index 2ed8f4bf..ee774901 100644 --- a/firmware/common/config/mathematics/group4_other.inc +++ b/firmware/common/config/mathematics/group4_other.inc @@ -26,3 +26,9 @@ MATHConvertNumberToString(DCOMMAND); DOCUMENTATION Convert the constant in Register1 to a length prefixed string which is stored at \Param{4,5} + + FUNCTION 35 Set Degree/Radian Mode + MATHSetAngleMeasure(DPARAMS[0] != 0); + DOCUMENTATION + Sets the use of degrees (the default) when non zero, radians when zero. + diff --git a/firmware/common/config/mathematics/group4_unary.inc b/firmware/common/config/mathematics/group4_unary.inc index 553656c7..85df49ed 100644 --- a/firmware/common/config/mathematics/group4_unary.inc +++ b/firmware/common/config/mathematics/group4_unary.inc @@ -41,27 +41,27 @@ FUNCTION 19 Sine f1 = MATHReadFloat(MATH_REG1); - MATHWriteFloat(sin(TORADIANS(f1)),MATH_REG1); + MATHWriteFloat(sin(MATHConvertAngleToDefault(f1)),MATH_REG1); DOCUMENTATION - Register1 := sine(Register 1) angles in degrees + Register1 := sine(Register 1) angles in degrees/radians FUNCTION 20 Cosine f1 = MATHReadFloat(MATH_REG1); - MATHWriteFloat(cos(TORADIANS(f1)),MATH_REG1); + MATHWriteFloat(cos(MATHConvertAngleToDefault(f1)),MATH_REG1); DOCUMENTATION - Register1 := cosine(Register 1) angles in degrees + Register1 := cosine(Register 1) angles in degrees/radians FUNCTION 21 Tangent f1 = MATHReadFloat(MATH_REG1); - MATHWriteFloat(tan(TORADIANS(f1)),MATH_REG1); + MATHWriteFloat(tan(MATHConvertAngleToDefault(f1)),MATH_REG1); DOCUMENTATION - Register1 := tangent(Register 1) angles in degrees + Register1 := tangent(Register 1) angles in degrees/radians FUNCTION 22 Arctangent f1 = MATHReadFloat(MATH_REG1); - MATHWriteFloat(FROMRADIANS(atan(f1)),MATH_REG1); + MATHWriteFloat(MATHConvertAngleFromDefault(atan(f1)),MATH_REG1); DOCUMENTATION - Register1 := arctangent(Register 1) angles in degrees + Register1 := arctangent(Register 1) angles in degrees/radians FUNCTION 23 Exponent f1 = MATHReadFloat(MATH_REG1); diff --git a/firmware/common/include/interface/maths.h b/firmware/common/include/interface/maths.h index 11da5a16..35928908 100644 --- a/firmware/common/include/interface/maths.h +++ b/firmware/common/include/interface/maths.h @@ -28,6 +28,10 @@ void MATHProcessDecimal(uint8_t *command); void MATHConvertStringToNumber(uint8_t *command); void MATHConvertNumberToString(uint8_t *command); +float MATHConvertAngleToDefault(float angle); +float MATHConvertAngleFromDefault(float angle); +void MATHSetAngleMeasure(bool bDegrees); + #endif // *************************************************************************************** diff --git a/firmware/common/sources/interface/maths.cpp b/firmware/common/sources/interface/maths.cpp index 503da94c..33b1c145 100644 --- a/firmware/common/sources/interface/maths.cpp +++ b/firmware/common/sources/interface/maths.cpp @@ -32,11 +32,34 @@ static union _regConvert { uint32_t i; } sc; +// +// Degrees / Radians flag. +// +static bool bUseDegrees = true; + // // Map offset to actual register start address (Placeholder) // #define REGADDR(ofst) (regAddress+(ofst)) +// *************************************************************************************** +// +// Handle degrees and radians +// +// *************************************************************************************** + +float MATHConvertAngleToDefault(float angle) { + return bUseDegrees ? angle * M_PI / 180.0 : angle; +} + +float MATHConvertAngleFromDefault(float angle) { + return bUseDegrees ? angle * 180.0 / M_PI : angle; +} + +void MATHSetAngleMeasure(bool bDegrees) { + bUseDegrees = bDegrees; +} + // *************************************************************************************** // // Read a register 1/2 into the conversion structure, returns control byte