Skip to content

Commit 4c0a87f

Browse files
committed
Document PROC parameters, use parameters in pi.bas sample.
1 parent a89cb15 commit 4c0a87f

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

manual.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Currently, FastBasic supports:
4040
255 characters.
4141
- Arrays of "word", "byte", floating
4242
point and strings.
43-
- User defined procedures.
43+
- User defined procedures, with integer
44+
parameters.
4445
- Compilation to binary loadable files.
4546
- Available as a full version `FB.COM`,
4647
as a smaller integer-only `FBI.COM`
@@ -1044,12 +1045,16 @@ Control Statements
10441045

10451046

10461047
**Calls A Subroutine**
1047-
**EXEC _name_ / EXE.**
1048+
**EXEC _name_ _num1_, ... / EXE.**
10481049

1049-
Calls the subroutine _name_. Note
1050-
that the subroutine must be defined
1051-
with PROC, but can be defined before
1052-
or after the call.
1050+
Calls the subroutine _name_, with the
1051+
optional parameters _num1_ and so on,
1052+
separated by commas.
1053+
1054+
Note that the subroutine must be
1055+
defined with PROC with the same number
1056+
of parameters, but can be defined
1057+
before or after the call.
10531058

10541059

10551060
**Exits From Loop Or PROC**
@@ -1165,13 +1170,26 @@ Control Statements
11651170

11661171

11671172
**Define A Subroutine.**
1168-
**PROC _name_ / PR.**
1173+
**PROC _name_ _var1_ .../ PR.**
11691174
**ENDPROC / ENDP.**
11701175

11711176
PROC statement starts the definition
11721177
of a subroutine that can be called
11731178
via EXEC.
11741179

1180+
You can pass a list of integer
1181+
variables separated by spaces after
1182+
the PROC name to specify a number of
1183+
parameters, the variables will be set
1184+
to the values passed by the EXEC call.
1185+
Those variable names are always
1186+
global, so the values set are seen
1187+
outside the PROC.
1188+
1189+
The number of parameters in the PROC
1190+
definition and in all the EXEC calls
1191+
must be the same.
1192+
11751193
Note that if the PROC statement is
11761194
encountered while executing
11771195
surrounding code, the full subroutine

samples/int/pi.bas

+14-22
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
DIM P(130), T(130) BYTE, SV(130) BYTE
1313

1414
' Arguments to procedures bellow
15-
MULT=0
16-
DIVI=0
1715
ZERO=0
1816

1917
' Precision in digit pairs
@@ -30,15 +28,15 @@ NEXT
3028

3129
' Calculate ATAN(1/5), positive:
3230
PRINT "A(1/5):";
33-
AS=1 : AT=5 : EXEC ARCTAN_SMALL
31+
EXEC ARCTAN_SMALL 1, 5
3432
PRINT
3533

3634
' Multiply by 4
3735
EXEC MUL4
3836

3937
' Calculate ATAN(1/239), negative:
4038
PRINT "A(1/239):";
41-
AS=0 : AT=239 : EXEC ARCTAN
39+
EXEC ARCTAN 0, 239
4240
PRINT
4341

4442
' Multiply all by 4
@@ -75,24 +73,21 @@ ENDPROC
7573
' Calculate ATAN(1/AT), adding the
7674
' result to P()
7775
'
78-
PROC ARCTAN
76+
PROC ARCTAN AS AT
7977
T(0)=1
8078
ZERO=0
81-
DIVI=AT
82-
EXEC DIV
79+
EXEC DIV AT
8380
EXEC SAVE_T
8481
N=1
8582
REPEAT
8683
EXEC ADDSUB
8784
EXEC RESTORE_T
88-
DIVI=AT
89-
EXEC DIV
90-
EXEC DIV
85+
EXEC DIV AT
86+
EXEC DIV AT
9187
EXEC SAVE_T
9288
EXEC CHKZERO
9389
N=N+2
94-
DIVI=N
95-
EXEC DIV
90+
EXEC DIV N
9691
PRINT ".";
9792
UNTIL ZERO<0
9893
ENDPROC
@@ -102,24 +97,21 @@ ENDPROC
10297
' number (so that AT*AT*100 < 32768),
10398
' adding the result to P().
10499
'
105-
PROC ARCTAN_SMALL
100+
PROC ARCTAN_SMALL AS AT
106101
T(0)=1
107102
ZERO=0
108-
DIVI=AT
109-
EXEC DIV
103+
EXEC DIV AT
110104
EXEC SAVE_T
111105
N=1
112106
AT=AT*AT
113107
REPEAT
114108
EXEC ADDSUB
115109
EXEC RESTORE_T
116110
N=N+2
117-
DIVI=AT
118-
EXEC DIV
111+
EXEC DIV AT
119112
EXEC CHKZERO
120113
EXEC SAVE_T
121-
DIVI=N
122-
EXEC DIV
114+
EXEC DIV N
123115
PRINT ".";
124116
UNTIL ZERO<0
125117
ENDPROC
@@ -204,10 +196,10 @@ ENDPROC
204196
' Multiplies T() by the small number
205197
' MULTI, only works if MULTI*100<32768
206198
'
207-
PROC MUL
199+
PROC MUL MULTI
208200
C=0
209201
FOR I=Q TO 0 STEP -1
210-
B = T(I) * MULT + C
202+
B = T(I) * MULTI + C
211203
T(I) = B MOD 100
212204
C = B / 100
213205
NEXT
@@ -217,7 +209,7 @@ ENDPROC
217209
' Divides T() by the small number DIVI,
218210
' only works if DIVI*100<32768
219211
'
220-
PROC DIV
212+
PROC DIV DIVI
221213
C=0
222214
FOR I=ZERO TO Q
223215
B = 100 * C + T(I)

0 commit comments

Comments
 (0)