List of replacement libraries:

- Delays library (__Lib_Delays)
- Strings library (__Lib_String)
- Conversions library (__Lib_Conversions)
- C_Stdlib library (__Lib_CStdlib)
- Internal EEPROM library (__Lib_EEPROM_256 and __Lib_EEPROM_1024)
- System library (__Lib_System)
- Fixed-point math library (__Lib_Math - two versions)
- Floating-point math library (__Lib_MathDouble - two versions)
- Floating-point functions library (__Lib_Trigon)
- Trigonometric functions library (__Lib_Trigonometry)

Newest version contains System and EEPROM libs' versions for PIC18FxxK40 processors (the problem present in original EEPROM libs is naturally fixed). Added is also a set of libraries for enhanced processor series that do not exhibit problems of official libraries.

A couple of short videos demonstrating the differences and ease of switching between official and replacement libs:

- switching between libs switching.avi
- Conversions library efficiency comparison Conversions.avi

Using the replacement libs with mB PRO.

**Delays** library replacement offers slight advantage in code size and decidedly more precise VDelay_ms and VDelay_Advanced_ms procedures, which are less dependent on chosen processor clock.

As the source is provided and all but one routine have same prototypes as the original, there was no need to prepare a separate documentation for this library. The additional routine, VDelay_us, allows to obtain variable delays in sub-millisecond range. It's been written in assembly, but it still has some limitations. Real 1us resolution and accuracy may be achieved only with clock frequencies in excess of 16MHz. You'll find additional information in the source file.

**Strings** library, prepared some time ago with yo2lio's help for PIC18 processors, has been later ported to mP PRO and expanded quite a bit by adding several Delphi-like routines.
The replacement routines are more effective, both in size and in execution time, than the
originals - that was the main reason to write them.

For those that use Florin's Ethernet libs a small library was added that should be used
instead of his Additional Strings Library (which cannot be used in parallel with the
Conversions lib replacement).
It contains just few routines that differ in naming from the Strings lib
replacement and are needed by Ethernet libs. It's naturally called the same as original (
pic_additional_string_library.mcl) as the Ethernet libs search for it.

Due to use of assembly, the

Read Conversions lib documentation

**C_Stdlib** library replacement contains two pseudo-random functions from the original library. It was introduced to make use of these functions possible as there was a conflict between the abs function contained in the original library and similarly named function in Math replacement library.

Both libraries contain the same routines, only adjusted for EEPROM size. Block read/write routines have been added to allow operation on blocks of data. One may read up to 256 bytes with EEPROM_readBlk to a RAM memory locations starting at an address specified by a pointer. The amount of data that can be stored with EEPROM_writeBlk function has been intentionally limited to 32 bytes.

Read EEPROM lib documentation

Besides some marginal optimisation, the main change introduced to

There is just one public routine in official System library – the Swap function, which is naturally preserved. Added public routine, FSRcontext, should be called to force the compiler to add FSR registers to context saving/restoring in ISRs. This may prove necessary if one used FSR registers directly in Pascal in both main code and ISR (or calls routines that do it). Naturally, one may perform the context saving by oneself, instead.

Starting from v. 6.40 two functions known from mC,

Read System lib documentation

Problems that were corrected:

- numbers of type short:
- - division by 0 gives -128, whatever the dividend's sign,
- - division of -128 by -1 gives -128,
- - division of positive odd and negative even numbers by -128 gives 1, not 0,
- division of integer by 0 gives maximum positive value, whatever the dividend's sign,
- division of longint by 0 gives maximum positive value, whatever the dividend's sign,
- modulo operation on signed types gives results with wrong sign if second operand is negative ('signed' division routines produce wrong sign of remainder if divisor is negative),
- modulo operation on minimal longint number produces results smaller by one in magnitude than valid ones,
- error specific to PIC16 and enhanced families: if divisor is zero and dividend is from RAM bank other than 0, some division routines may lead to memory corruption.

Naturally, I could not do anything about the fact that compiler never calls signed multiplication routines for 16- and 32-bit integers (the routines are there, compiler simply does not call them as, due to errors in original signed routines, unsigned multiplication routines are called instead).

Note that problems with modulo operations, besides leading to wrong results, lead also to
discrepancies between compilation-time calculations and runtime ones.

Some public routines were added to the Math library. Four of them help to exploit the
exception mechanism (or just use the status byte of fixed-point calculations). There are
also absolute value and square root functions as well as two additional execution-time
effective multiplication routines.

The library defines also constants representing integral types' range limits.

**Floating-point math** library replacement has also two versions - both produce smaller
code than the official one and give more accurate calculation results by fixing problems
that the official lib inherited from the original Microchip library, i.e.

- lack of 'unbiased' rounding,
- lack of rounding while converting to integer types,
- lack of big numbers 'rounding', i.e. conversion error reduction,
- max negative number reported as integer overflow,
- unpredictable result of conversion of real to dword number (PIC16 & enhanced)
- overflow sign not dependent on dividend for division by zero,
- several problems with calculations close to range limits,
- no protection against numbers with EXP=0 and significand<>0 that do not belong to Microchip format.

Both versions give access to floating-point operations' status byte. One of them may generate 'exceptions', i.e. allows to write code that contains provisions for calculation errors (like overflow, underflow, or division by zero). The library requires presence of appropriate version of Math library replacement.

Read MathDouble lib documentation**Floating-point functions** libraries, Trigon and Trigonometry, were prepared to work
with MathDouble replacement of mE's system floating-point library (__Lib_MathDouble.mcl).
Please do not use them separately, i.e. with the original MathDouble lib.
Moreover, the Trigon library requires presence of other replacement libs, namely the
Strings and Conversions libraries.

Both f-p functions libs contain all the routines present in the originals (though differently distributed)
plus a set of routines that were formerly contained in an additional lib, called Fpmath
and distributed with earlier MathDouble lib replacement versions (up to v 0.07).
The replacement libraries produce smaller code than the originals, while giving more
accurate calculation results, and allow to exploit the exception mechanism from
Math and MathDouble lib replacements.
Detailed differences from the originals:

- exception mechanism for f-p math errors,
- NaN (Not a Number) bit set in FPstatus for negative arguments in Sqrt and in pow(x,y) when x is negative and y is not an integral number,
- added routines: rSgn, rAbs, Round, Trunc, Int, Frac, rFrexp, rMin, rMax, Sqr, conversion routines to/from string & IEEE 754 format,
- corrected errors in atan2 function,
- most functions are noticeably faster, some, like Sqrt - much faster.

Due to introduction of rounding while converting to integer types (in both implicit and
explicit conversion), use of the replacement libs may require older code correction,
as with the official MathDouble lib conversion was based on truncation (the fractional part
of real number was simply omitted). This issue is addressed by introducing a set of useful
routines to the Trigon library – one of them, Trunc, may be used whenever rounding is not
wanted. (There is also Round function which does nothing more than explicit conversion but
was added for completeness.)

For clarity and ease of use, strictly trigonometric functions were moved from Trigon to
Trigonometry library. All functions contained in the latter are present in official
libraries and as such are documented in Help.

Apart from the programming language syntax, mB PRO is identical to mP PRO in all practical aspects, like program structure, language elements, libraries structure and contents (in fact almost all mB libs are written in Pascal and assembly). Therefore, precompiled replacement libs may freely be used with mB PRO. System libs, like System, Math or MathDouble will mostly work in background, and other libs require only understanding of their procedures and functions prototypes - and only those that are absent in original libs and thus missing from Help (and for the Delays lib replacement there is a source file in Basic). __Replacement libraries documentation installed by LibsSwitch for mB PRO lists the prototypes in Basic.__

For those that want to take a look at documentation for mP linked to on this page, here are few tips about the syntax differences:

- parameter passed by value Pascal bb: byte Basic dim bb as byte - parameter passed by address (reference) Pascal var bb: byte Basic dim byref bb as byte - parameters are separated by colons in Basic while in Pascal also semicolons are used Pascal procedure example(a1,a2: byte; var w1: word); Basic sub procedure example(dim a1,a2 as byte, dim byref w1 as word) - simple types' names are identical in both languages except for longword (dword) and float (real) - strings and pointers are declared in the same way in both languages while arrays a bit differently Pascal arr: array[5] of byte Basic dim arr as byte[5]Examples:

procedure CopyC(var Dest:string; Source: ^const char; Index,Count: word); sub procedure CopyC(dim byref Dest as string, dim Source as ^const char, dim Index,Count as word) function str2real(var inst: string[17]): real; sub function str2real(dim byref inst as string[17]) as real