docs: add more info about sets and for-in loop
This commit is contained in:
parent
573b28bd21
commit
796d8f8e5f
2 changed files with 57 additions and 3 deletions
|
|
@ -20,7 +20,38 @@ Note that the **char** type is a 32-bit type, and strings contain bytes. Non-ASC
|
||||||
When indexing a string, the result is a **char** type with bits 31 to 8 set to zero. When assigning a **char** to an indexed string element, the destination byte is set to bits 7 to 0 from the **char** variable. Bits 31 to 8 are ignored.
|
When indexing a string, the result is a **char** type with bits 31 to 8 set to zero. When assigning a **char** to an indexed string element, the destination byte is set to bits 7 to 0 from the **char** variable. Bits 31 to 8 are ignored.
|
||||||
|
|
||||||
## For-in Loop
|
## For-in Loop
|
||||||
The for-in-loop which allows iterating over a string or a linear array of scalar variables is supported. It is more efficient than using a for loop for indexing a string or an array, because no bounds checks are needed.
|
The for-in-loop is supported, which allows iterating over a string or a linear array of scalar variables. It is more efficient than using a for loop for indexing a string or an array, because no bounds checks are needed on each iteration.
|
||||||
|
|
||||||
|
String Example:
|
||||||
|
```
|
||||||
|
var s:string;
|
||||||
|
c:char;
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
s := 'Test';
|
||||||
|
|
||||||
|
for c in s do
|
||||||
|
writeln(ord(c));
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Array Example:
|
||||||
|
```
|
||||||
|
var a:array [1..3] of integer;
|
||||||
|
i:integer;
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
a[1] := 3; a[3] := 2; a[5] := 1;
|
||||||
|
|
||||||
|
for i in a do
|
||||||
|
writeln(i);
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Sets
|
## Sets
|
||||||
The maximum number of elements in a set is 32. This makes a SET OF CHAR impossible.
|
The maximum number of elements in a set is 32. This makes a SET OF CHAR impossible.
|
||||||
|
|
@ -39,9 +70,32 @@ The _in_ operator also works for linear arrays, so the _if_ statement will have
|
||||||
|
|
||||||
Note that the array _in_ operator will be more inefficient for larger ranges (i.e. `'A'..'z'`), but more efficient for sparse sets (i.e. `'A','z'`).
|
Note that the array _in_ operator will be more inefficient for larger ranges (i.e. `'A'..'z'`), but more efficient for sparse sets (i.e. `'A','z'`).
|
||||||
|
|
||||||
|
A set literal can only appear on the right side of an assignment to a set variable, or when passing an argument of a set type to a procedure/function.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
program settest;
|
||||||
|
type weekday = (Mon,Tue,Wed,Thu,Fri,Sat,Sun);
|
||||||
|
days = set of weekday;
|
||||||
|
|
||||||
|
var s:days;
|
||||||
|
d:weekday;
|
||||||
|
|
||||||
|
begin
|
||||||
|
s := [Sat,Sun]; (* set literal *)
|
||||||
|
|
||||||
|
d := Sun;
|
||||||
|
if d in [Sat,Sun] then (* array literal, IN operator for arrays *)
|
||||||
|
writeln('weekend');
|
||||||
|
|
||||||
|
if d in s then (* IN operator for sets *)
|
||||||
|
writeln('also weekend');
|
||||||
|
end.
|
||||||
|
```
|
||||||
|
|
||||||
## Break and Continue Statements
|
## Break and Continue Statements
|
||||||
|
|
||||||
Wirth Pascal has no statement to exit a loop. Other Pascal dialects have the _break_ and _continue_ statements to exit the loop or skip to the next iteration.
|
Wirth Pascal has no statement to exit a loop other than the loop condition. Other Pascal dialects have the _break_ and _continue_ statements to exit the loop or skip to the next iteration.
|
||||||
|
|
||||||
Tridora-Pascal only supports the _break_ statement at the moment.
|
Tridora-Pascal only supports the _break_ statement at the moment.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ Video memory uses a linear layout, with words using an address increment of one.
|
||||||
The first word (horizontal pixel coordinates 0-3) is at address 0, the second (coordinates 4-7) at address 1 etc.
|
The first word (horizontal pixel coordinates 0-3) is at address 0, the second (coordinates 4-7) at address 1 etc.
|
||||||
The first line starts at address 0, the second at address 80 etc.
|
The first line starts at address 0, the second at address 80 etc.
|
||||||
|
|
||||||
To access video memory, the corresponding video memory address must be written to a latch register, then pixel data can be read or written by the I/O register. Reading and writing uses separate latch registers (the "Read Adress" and "Write Address" registers. To read the same word and write it back, both addresses need to be set.
|
To access video memory, the corresponding video memory address must be written to a latch register, then pixel data can be read or written by the I/O register. Reading and writing uses separate latch registers (the "Read Adress" and "Write Address" registers, _FB_RA_ and _FB_WA_). To read the same word and write it back, both addresses need to be set.
|
||||||
Both registers have an auto-increment function. After reading the I/O register, the FB_RA register is ingremented by one. After writing to the I/O register, the FB_WA register is incremented by one.
|
Both registers have an auto-increment function. After reading the I/O register, the FB_RA register is ingremented by one. After writing to the I/O register, the FB_WA register is incremented by one.
|
||||||
|
|
||||||
## Palette Data
|
## Palette Data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue