Skip to content

Commit c35e7e9

Browse files
authored
Merge pull request #986 from boriel-basic/docs
Docs
2 parents 9445b12 + 9e3a422 commit c35e7e9

File tree

6 files changed

+118
-93
lines changed

6 files changed

+118
-93
lines changed

docs/cos.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Argument must be a numeric expression in radians units. Returned value type is [
1414

1515
## Examples
1616

17-
```
17+
```basic
1818
REM Cosine value
1919
PRINT "Cosine value of a is "; COS(a)
2020
```
@@ -30,4 +30,4 @@ PRINT "Cosine value of a is "; COS(a)
3030
* [SIN](sin.md) and [ASN](asn.md)
3131
* [TAN](tan.md) and [ATN](atn.md)
3232
* [ACS](acs.md)
33-
* Faster library option for lower accuracy trigonometry for games: [FCOS](fsin.bas.md)
33+
* Faster library option for lower accuracy trigonometry for games: [FCOS](library/fsin.bas.md)

docs/index.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# General
1+
## General
2+
23
* [About](about.md)
34
<br />About Boriel BASIC SDK
45

@@ -14,18 +15,17 @@
1415
* [Command line options](zxb.md#Command_Line_Options)
1516
<br />Command line options table for the compiler (zxb)
1617

17-
# Download
18-
18+
## Download
1919
Get the latest version of Boriel BASIC from the [archive](archive.md).
2020

21-
# Released programs
21+
## Released programs
2222

2323
* [Released programs](released_programs.md)
2424
<br />A list of third-party released programs (mostly games) for the ZX-Spectrum developed with Boriel BASIC.
2525

26-
# Learning Boriel BASIC
26+
## Learning Boriel BASIC
2727

28-
## Language Reference
28+
### Language Reference
2929
* [Language syntax](syntax.md)
3030
<br />Language Syntax is very close to the original Sinclair BASIC, but it's expanded and enhanced.
3131

@@ -38,7 +38,7 @@ Get the latest version of Boriel BASIC from the [archive](archive.md).
3838
* [Standard libraries](library/stdlib.md)
3939
<br />Standard libraries that comes bundled with Boriel BASIC compiler.
4040

41-
## Tutorials
41+
### Tutorials
4242
* [Programming tutorials](tutorials.md)
4343
<br />A collection of third-party tutorials about development with Boriel BASIC.
4444

@@ -48,31 +48,32 @@ Get the latest version of Boriel BASIC from the [archive](archive.md).
4848
* [Sample Games](sample_programs.md#Game Examples)
4949
<br />Some little games examples.
5050

51-
# Help and Support
51+
## Help and Support
5252

5353
* [Community Forum](http://www.boriel.com/forum)
5454
<br />Have a question? Need help or comment a report a bug? Go to the [Boriel BASIC forum](http://www.boriel.com/forum)
5555

56-
# External resources
56+
## External resources
5757

5858
* Here you are [external resources](external_resources.md): other tools, IDEs, graphic designers and projects related to Boriel BASIC. Have a look!
5959

60-
# External libraries
60+
### External libraries
6161

6262
* [Library](library.md)
6363
<br />Library of functions and subroutines you can use in your programs. You might find them really useful.
6464

65-
# Inline assembler
65+
## Inline assembler
6666
Embedding inline assembler in your code is pretty easy. There's a [tutorial](tutorials.md) on it.
6767

68-
# Compiler internals
68+
## Compiler internals
6969
Only for true hackers: This explains how the compiler does its job, how to expand it, etc.
70+
This is `work in progress`.
7071

71-
# Other Architectures
72+
## Other Architectures
7273
Boriel BASIC was designed from the base as a Retargeable Compiler, so it should be not hard to extend
7374
it to other architectures. This is `work in progress`. See [other architectures](other_architectures.md) for more info.
7475

75-
# Contributing
76+
## Contributing
7677
You can issue a Pull Request to the [GitHub repository](https://github.com/boriel/zxbasic), report bugs in the forum
7778
when using the compiler, suggest new features...
7879

docs/library/fsin.bas.md

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,91 @@
22

33
## Introduction
44

5+
This function implements fast `Fixed` point `sin`, `cos` and `tan` functions.
6+
The ones that uses `Float` type (calling the Sinclair ROM) are much slower as FP Calculations
7+
are expensive. This variant is less precise but more suitable for games, for example.
8+
59
`fSin` is the basis for the alternatives, since `COS(x)` can be calculated
6-
from `SIN(x)` and `TAN(x)` from `COS(x)` and `SIN(x)`.
10+
from `SIN(x)` and `TAN(x)` as `SIN(x)` / `COS(x)`.
11+
12+
!!! info "Note"
13+
This library is already bundled with Boriel BASIC.<br />
14+
To use it just add `#include <fmath.bas>`
15+
at the beginning of your program.
716

817
The functions should be accurate to about 0.25%, and significantly faster.
918
If you need a lot of trig in your code, and it doesn't need to be pinpoint accuracy, these are good alternatives.
10-
Note that they more or less acknowledge they are less accurate by returning values of type `Fixed` instead of type `Float`.
11-
I did this because it should be fine for the actual accuracy returned,
19+
Note that they more or less acknowledge they are less accurate by returning values of type `Fixed` instead
20+
of type `Float`.
21+
It should be fine for the actual accuracy returned,
1222
and `Fixed` numbers process faster and smaller than `Float` ones.
1323

14-
* Note that you need only include `fSin` if you only want Sines, but you need fSin to use `fCos` or `fTan`.
24+
* Note that you need only include `fSin` if you only want Sines, but you need `fSin` to use `fCos` or `fTan`.
1525

1626
* Note that these functions use degrees, not radians.
1727

1828
## SINE Function
1929

20-
```
30+
```vbnet
2131
FUNCTION fSin(num as FIXED) as FIXED
22-
DIM quad as byte
23-
DIM est1,dif as uByte
24-
25-
'This change made now that MOD works with FIXED types.
26-
'This is much faster than the repeated subtraction method for large angles (much > 360)
27-
'while having some tiny rounding errors that should not significantly affect our results.
28-
'Note that the result may be positive or negative still, and for SIN(360) might come out
29-
'fractionally above 360 (which would cause issued) so the below code still is required.
30-
31-
IF num >= 360 THEN
32-
num = num MOD 360
33-
ELSEIF num < 0 THEN
34-
num = 360 - ABS(num) MOD 360
35-
END IF
36-
37-
IF num>180 then
38-
quad=-1
39-
num=num-180
40-
ELSE
41-
quad=1
42-
END IF
43-
44-
IF num>90 then num=180-num
45-
46-
num=num/2
47-
dif=num : rem Cast to byte loses decimal
48-
num=num-dif : rem so this is just the decimal bit
49-
50-
51-
est1=PEEK (@sinetable+dif)
52-
dif=PEEK (@sinetable+dif+1)-est1 : REM this is just the difference to the next up number.
53-
54-
num=est1+(num*dif): REM base +interpolate to the next value.
55-
56-
return (num/255)*quad
57-
58-
59-
sinetable:
60-
asm
61-
DEFB 000,009,018,027,035,044,053,062
62-
DEFB 070,079,087,096,104,112,120,127
63-
DEFB 135,143,150,157,164,171,177,183
64-
DEFB 190,195,201,206,211,216,221,225
65-
DEFB 229,233,236,240,243,245,247,249
66-
DEFB 251,253,254,254,255,255
67-
end asm
32+
DIM quad as byte
33+
DIM est1,dif as uByte
34+
35+
'This change made now that MOD works with FIXED types.
36+
'This is much faster than the repeated subtraction method for large angles (much > 360)
37+
'while having some tiny rounding errors that should not significantly affect our results.
38+
'Note that the result may be positive or negative still, and for SIN(360) might come out
39+
'fractionally above 360 (which would cause issued) so the below code still is required.
40+
41+
IF num >= 360 THEN
42+
num = num MOD 360
43+
ELSEIF num < 0 THEN
44+
num = 360 - ABS(num) MOD 360
45+
END IF
46+
47+
IF num > 180 then
48+
quad = -1
49+
num = num - 180
50+
ELSE
51+
quad = 1
52+
END IF
53+
54+
IF num > 90 THEN num = 180 - num
55+
56+
num = num / 2
57+
dif = num : REM Cast to byte loses decimal
58+
num = num - dif : REM so this is just the decimal bit
59+
60+
est1 = PEEK(@sinetable + dif)
61+
dif = PEEK(@sinetable + dif + 1) - est1 : REM this is just the difference to the next up number.
62+
num = est1 + (num * dif) : REM base + interpolate to the next value.
63+
64+
Return (num / 255) * quad
65+
66+
sinetable:
67+
Asm
68+
DEFB 000,009,018,027,035,044,053,062
69+
DEFB 070,079,087,096,104,112,120,127
70+
DEFB 135,143,150,157,164,171,177,183
71+
DEFB 190,195,201,206,211,216,221,225
72+
DEFB 229,233,236,240,243,245,247,249
73+
DEFB 251,253,254,254,255,255
74+
End Asm
6875
END FUNCTION
6976
```
7077

7178
## COSINE Function
7279

73-
```
80+
```vbnet
7481
FUNCTION fCos(num as FIXED) as FIXED
75-
return fSin(90-num)
82+
Return fSin(90 - num)
7683
END FUNCTION
7784
```
7885

7986
## TANGENT Function
8087

81-
```
88+
```vbnet
8289
FUNCTION fTan(num as FIXED) as FIXED
83-
return fSin(num)/fSin(90-num)
90+
Return fSin(num) / fSin(90 - num)
8491
END FUNCTION
8592
```

docs/overrides/stylesheets/extra.css

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@
99
/* Apply Sinclair Logo font to the main header */
1010
/* Light mode - very light yellow header */
1111
[data-md-color-scheme="default"] .md-header {
12-
background-color: #264eb2; /* Very light yellow background color */
12+
background-color: #d0d6da; /* Very light yellow background color */
13+
height: 4rem;
1314
}
1415

1516

1617
[data-md-color-scheme="default"] .md-header__title {
17-
color: #ffde06;
18+
color: #23231c;
19+
padding-left: 2rem;
1820
}
1921

2022
/* Dark mode - dark gray header */
2123
[data-md-color-scheme="slate"] .md-header {
2224
background-color: #333333; /* Dark gray background color */
25+
/*background-image: url('../img/boriel-basic-sinclair.png');*/
26+
/*background-repeat: no-repeat;*/
27+
/*background-position: center center;*/
28+
/*background-size: auto 90%;*/
29+
height: 4rem;
2330
}
2431

2532
[data-md-color-scheme="slate"] .md-header__title {
2633
color: #af0d0d;
34+
padding-left: 2rem;
2735
}
2836

2937
.md-header__title {
@@ -40,11 +48,13 @@
4048
background-repeat: no-repeat;
4149
background-position: left center;
4250
background-size: auto 100%;
51+
height: 100%;
4352
}
4453

4554
/*!* Make the logo size 100% of the header *!*/
4655
.md-header__button.md-logo {
4756
color: #ff000000;
57+
height: 100%;
4858
}
4959

5060
/* Increase font weight for headings */
@@ -54,11 +64,16 @@ h1, h2, h3, h4, h5, h6 {
5464
}
5565

5666
/* Target Material theme specific heading classes if any */
57-
.md-typeset h1,
58-
.md-typeset h2,
59-
.md-typeset h3,
60-
.md-typeset h4,
61-
.md-typeset h5,
67+
.md-typeset h1,
68+
.md-typeset h2,
69+
.md-typeset h3,
70+
.md-typeset h4,
71+
.md-typeset h5,
6272
.md-typeset h6 {
6373
font-weight: 600; /* Bold */
6474
}
75+
76+
.md-typeset .admonition,
77+
.md-typeset details {
78+
font-size: 0.75rem
79+
}

docs/types.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Types
22

3-
## Introductions
3+
## Introduction
44

55
Although ZX BASIC was originally designed with ZX Spectrum in mind, it is a three-stage _retargeable_ compiler. This means it should not be difficult to hack ZX BASIC SDK to compile for other target machines (E.g. Commodore 64) or current machines (PC) or even virtual machines like Java or .NET. Porting ZX BASIC to other Z80 architectures like Amstrad or MSX should be almost straightforward (only the library.asm should need some work to use different ROM routines).
66

@@ -25,14 +25,14 @@ They can be _unsigned_ (their value is always 0 or positive) or _signed_ (can ta
2525
ZX Basic integer types sizes are 8, 16 and 32 bits. Unsigned types have the prefix _U_.
2626

2727

28-
| Type name | Size (bytes) | Signed? | Range | Description |
29-
|:-----------|:-----:|:--------:|:------:|:-------------|
30-
| Byte | 1 | yes | -128..127 | 8 bits signed integer |
31-
| UByte| 1 | no | 0..255 | 8 bits unsigned integer |
32-
| Integer | 2 | yes | -32768..32767 | 16 bits signed integer |
33-
| UInteger | 2 | no | 0..65535 | 16 bits unsigned integer |
34-
| Long | 4 | yes | <small>−2,147,483,648 .. +2,147,483,647</small> | 32 bit signed integer |
35-
| ULong | 4 | yes | <small>0 .. 4,294,967,295</small>| 32 bit unsigned integer |
28+
| Type name | Size (bytes) | Signed? | Range | Description |
29+
|:----------|:------------:|:-------:|:-----------------------------------------------:|:-------------------------|
30+
| Byte | 1 | yes | -128..127 | 8 bits signed integer |
31+
| UByte | 1 | no | 0..255 | 8 bits unsigned integer |
32+
| Integer | 2 | yes | -32768..32767 | 16 bits signed integer |
33+
| UInteger | 2 | no | 0..65535 | 16 bits unsigned integer |
34+
| Long | 4 | yes | <small>−2,147,483,648 .. +2,147,483,647</small> | 32 bit signed integer |
35+
| ULong | 4 | yes | <small>0 .. 4,294,967,295</small> | 32 bit unsigned integer |
3636

3737

3838
### Decimals
@@ -41,7 +41,7 @@ Their sizes are 32 bit for `Fixed` type and 40 bits for `Float` one.
4141

4242
#### Fixed
4343
32 bit Fixed Point decimal. First 16 bits are the integer part, whilst remaining 16 contains the decimal one.
44-
Ranges from -32767.9999847 to 32767.9999847 with a precision of 1 / 2^16 (0.000015 approx.).
44+
Ranges from `-32767.9999847` to `32767.9999847` with a precision of 1 / 2<sup>16</sup> (0.000015 approx.).
4545
Fixed points decimal are less precise than Floating ones, but much faster and requires
4646
less space (1 byte less). Also, their range is much limited.
4747
They're usually used on screen drawing when Floating point is too slow and decimal
@@ -50,7 +50,8 @@ calculations are required.
5050
#### Float
5151
Floating point type is **identical** to the Sinclair BASIC one.
5252
It requires 5 bytes (1 byte for exponent, 4 bytes for mantissa).
53-
Read the ZX Spectrum manual or [here](http://www.worldofspectrum.org/ZXBasicManual/zxmanchap24.html).
53+
Read the [Chapter 24 of the ZX Spectrum manual](http://www.worldofspectrum.org/ZXBasicManual/zxmanchap24.html)
54+
for further information.
5455

5556
>To store the number in the computer, we use five bytes, as follows:
5657
>
@@ -75,7 +76,7 @@ At this moment, ZX BASIC is not an <abbr title="Object Oriented Programming">OOP
7576
Vars are _scalar_ variables. Scalar variables are those which store a single value.
7677
Almost all variables are scalars:
7778

78-
```
79+
```basic
7980
REM A simple scalar variable
8081
DIM a = 3
8182
```
@@ -85,7 +86,7 @@ DIM a = 3
8586
Unlike scalars, array variables can hold more than a single value at once.
8687
You access a single value within the array container using an integer _index_:
8788

88-
```
89+
```basic
8990
REM An array variable
9091
DIM a(1 TO 10) AS UBYTE
9192
LET a(3) = 5: REM pick a(3) cell and store the number 5 in it
@@ -97,7 +98,7 @@ Unlike the above, [labels](labels.md) are not variables.
9798
They refer to memory positions. Line numbers are also treated as labels and they are completely optional:
9899

99100

100-
```
101+
```basic
101102
10 REM here '10' is a Label
102103
5 REM here '5' is another label, so the number order does not matter
103104
REM Line numbers are optional. So this line is ok either.

0 commit comments

Comments
 (0)