Skip to content

Commit

Permalink
Merge pull request #413 from paulscottrobson/radians
Browse files Browse the repository at this point in the history
Deg/Rad enhancement
  • Loading branch information
paulscottrobson authored Apr 4, 2024
2 parents 0d0a732 + e0e7b3f commit 82ae53f
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 18 deletions.
8 changes: 8 additions & 0 deletions basic/sources/commands/base/clear.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 24 additions & 1 deletion basic/test.bsc
Original file line number Diff line number Diff line change
@@ -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)

13 changes: 8 additions & 5 deletions documents/release/source/api.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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} | }
Expand Down
2 changes: 0 additions & 2 deletions firmware/common/config/defines.inc

This file was deleted.

2 changes: 0 additions & 2 deletions firmware/common/config/dispatch.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// ***************************************************************************************
// ***************************************************************************************

include defines.inc

include system/group1_system.inc
include display/group2_console.inc
include system/group3_fileio.inc
Expand Down
6 changes: 6 additions & 0 deletions firmware/common/config/mathematics/group4_other.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

16 changes: 8 additions & 8 deletions firmware/common/config/mathematics/group4_unary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions firmware/common/include/interface/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ***************************************************************************************
Expand Down
23 changes: 23 additions & 0 deletions firmware/common/sources/interface/maths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82ae53f

Please sign in to comment.