passing_20floating-point_20values_20to_20dlls
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
passing_20floating-point_20values_20to_20dlls [2018/03/31 13:19] – external edit 127.0.0.1 | passing_20floating-point_20values_20to_20dlls [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
//by Richard Russell, July 2009//\\ \\ The majority of functions that you are likely to want to call using [[http:// | //by Richard Russell, July 2009//\\ \\ The majority of functions that you are likely to want to call using [[http:// | ||
==== 64-bit doubles passed by reference ==== | ==== 64-bit doubles passed by reference ==== | ||
- | \\ This is the simplest case to deal with in BB4W. Suppose you want to pass the variable **fpv**:\\ \\ | + | \\ This is the simplest case to deal with in BB4W. Suppose you want to pass the variable **fpv**: |
+ | |||
+ | <code bb4w> | ||
fpv# = fpv * 1.0# | fpv# = fpv * 1.0# | ||
SYS " | SYS " | ||
- | Here the value is converted (if necessary) to a 64-bit float (by multiplying it by **1.0#**) and then stored in the 64-bit variable **fpv#**. The parameter supplied in the SYS call is the address of the variable (**^fpv# | + | </ |
+ | |||
+ | Here the value is converted (if necessary) to a 64-bit float (by multiplying it by **1.0#**) and then stored in the 64-bit variable **fpv#**. The parameter supplied in the SYS call is the address of the variable (**^fpv# | ||
+ | |||
+ | <code bb4w> | ||
fpv#() *= 1.0# | fpv#() *= 1.0# | ||
SYS " | SYS " | ||
- | Here it is assumed that the array was originally declared with 64-bit elements (i.e. either in ***FLOAT 64** mode or by explicitly specifying a **#** suffix).\\ \\ If your array uses suffices starting at **1** rather than 0 then you will need to pass the address of the base element:\\ \\ | + | </ |
+ | |||
+ | Here it is assumed that the array was originally declared with 64-bit elements (i.e. either in ***FLOAT 64** mode or by explicitly specifying a **#** suffix).\\ \\ If your array uses suffices starting at **1** rather than 0 then you will need to pass the address of the base element: | ||
+ | |||
+ | <code bb4w> | ||
fpv#() *= 1.0# | fpv#() *= 1.0# | ||
SYS " | SYS " | ||
- | \\ | + | </ |
==== 64-bit doubles passed by value ==== | ==== 64-bit doubles passed by value ==== | ||
- | \\ Since each parameter of the **SYS** statement is passed as a 32-bit value, a 64-bit floating-point value must be passed as **two** parameters. Suppose you want to pass the variable **fpv**:\\ \\ | + | \\ Since each parameter of the **SYS** statement is passed as a 32-bit value, a 64-bit floating-point value must be passed as **two** parameters. Suppose you want to pass the variable **fpv**: |
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
- | The ' | + | </ |
+ | |||
+ | The ' | ||
+ | |||
+ | <code bb4w> | ||
fpv# = fpv * 1.0# | fpv# = fpv * 1.0# | ||
SYS " | SYS " | ||
- | \\ | + | </ |
==== 32-bit floats passed by reference ==== | ==== 32-bit floats passed by reference ==== | ||
- | \\ BBC BASIC for Windows doesn' | + | \\ BBC BASIC for Windows doesn' |
+ | |||
+ | <code bb4w> | ||
temp% = FN_f4(fpv) | temp% = FN_f4(fpv) | ||
SYS " | SYS " | ||
+ | </ | ||
+ | |||
Here the temporary variable **temp%** is loaded with the 32-bit float, and then its address is passed as the parameter.\\ \\ | Here the temporary variable **temp%** is loaded with the 32-bit float, and then its address is passed as the parameter.\\ \\ | ||
==== 32-bit floats passed by value ==== | ==== 32-bit floats passed by value ==== | ||
- | \\ This is similar to the previous case, except that the temporary variable is not required. So to pass the variable **fpv** by value:\\ \\ | + | \\ This is similar to the previous case, except that the temporary variable is not required. So to pass the variable **fpv** by value: |
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
+ | </ | ||
+ | |||
The ' | The ' | ||
==== Helper functions ==== | ==== Helper functions ==== | ||
- | \\ Here are the functions used in the above examples:\\ \\ | + | \\ Here are the functions used in the above examples: |
- | REM Convert to 64-bit double (low 4 bytes) | + | |
- | DEF FN_dl(A#) | + | <code bb4w> |
- | A# *= 1.0# | + | |
- | = !^A# | + | DEF FN_dl(A#) |
+ | A# *= 1.0# | ||
+ | = !^A# | ||
- | | + | |
- | DEF FN_dh(A#) | + | DEF FN_dh(A#) |
- | A# *= 1.0# | + | A# *= 1.0# |
- | = !(^A#+4) | + | = !(^A#+4) |
- | | + | |
- | DEF FN_f4(A#) | + | DEF FN_f4(a#)LOCALP%:P%=^a#: |
- | LOCAL A%,P% | + | =P%!4 AND NOT& |
- | PRIVATE F% | + | </ |
- | IF F%=0 THEN | + | |
- | | + | |
- | [OPT 2 | + | |
- | .F% | + | |
- | mov esi,[ebp+2]:mov edi, | + | |
- | fld qword [esi]:fstp dword [edi] | + | |
- | ret | + | |
- | ] | + | |
- | ENDIF | + | |
- | A# *= 1.0# | + | |
- | CALL F%,A#,A% | + | |
- | =A% | + |
passing_20floating-point_20values_20to_20dlls.1522502372.txt.gz · Last modified: 2024/01/05 00:17 (external edit)